<template>
  <TreeTableLayout>
    <template #tree>
      <Tree @query="doQuery" @gateway="getGateway" :gatewayType="1"></Tree>
    </template>
    <template #table>
      <RightTableLayout :slotName="['operation', 'table', 'pagination']">
        <template #operation>
          <div :class="{ btnbox: pid }">
            <div class="top tops">
              <el-row>
                <el-col :span="24">
                  <span :span="5">
                    <span class="tips">{{ i18n.fy.灯控操作 }}</span>
                    <el-select style="width: 120px" v-model="area" class="m-2" placeholder="" @change="changeArea()">
                      <el-option v-for="item in darrOptions" :key="item.value" :label="item.label"
                        :value="item.value" />
                    </el-select>
                  </span>
                  <span :span="4" v-if="area != ''" style="display: none">
                    <span>{{ i18n.fy.网关 }}</span>
                    <el-select style="width: 120px" disabled v-model="gateway" class="m-2" placeholder="">
                      <el-option :label="i18n.fy.全部网关" :value="''" />
                      <el-option v-for="item in gatewayList" :key="item.id" :label="item.title" :value="item.id" />
                    </el-select>
                  </span>
                  <span :span="3" v-if="area != ''">
                    <span>{{ i18n.fy.区 }}</span>
                    <el-select v-model="district" :placeholder="i18n.fy.区" style="width: 100px">
                      <el-option v-for="item in deviceAreaAllList" :value="item.area_code">
                        {{ item.area_code }}
                      </el-option>
                    </el-select>
                  </span>
                  <span :span="3" v-if="area != '' && area == '300'">
                    <span>
                      {{ i18n.language === "zh-cn" ? "标签" : "label" }}
                    </span>
                    <el-input style="width: 100px" v-model="tag" placeholder="" />
                  </span>
                  <span :span="3" v-if="area != '' && area == '200'">
                    <span>
                      {{ i18n.language === "zh-cn" ? "组" : "group" }}
                    </span>
                    <el-select v-model="group" placeholder="" style="width: 100px">
                      <el-option v-for="item in options" :value="item.group_name">{{ item.group_name }} </el-option>
                    </el-select>
                  </span>
                  <span :span="3" v-if="area != '' && area == '100'">
                    <span>
                      {{ i18n.language === "zh-cn" ? "号" : "name" }}
                    </span>
                    <el-input style="width: 100px" v-model="num" placeholder="" />
                  </span>
                  <span :span="10">
                    <el-button type="primary" @click="Everbright('lightOn')">{{ i18n.fy.常亮 }}</el-button>
                    <el-button type="primary" @click="extinction('lightOff')">{{ i18n.fy.常灭 }}</el-button>
                    <el-button type="primary" @click="flash('blink')">
                      {{ i18n.language === "zh-cn" ? "闪一闪" : "Twinkle" }}
                    </el-button>
                    <el-button type="primary" @click="stopFlash('stopBlink')">
                      {{ i18n.language === "zh-cn" ? "停止闪" : "Stop flashing" }}
                    </el-button>
                    <el-button type="primary" @click="dormancy('lightSleep')">
                      {{ i18n.language === "zh-cn" ? "休眠" : "hibernate" }}
                    </el-button>
                    <el-button type="primary" @click="newAdd()">
                      {{ i18n.language === "zh-cn" ? "新增灯" : "Addlights" }}
                    </el-button>
                    <el-button type="danger" @click="unbind">
                      {{ i18n.language === "zh-cn" ? "批量删除" : "BatchDelete" }}
                    </el-button>
                    <el-button type="primary" @click="updateCustomName">
                      {{ i18n.language === "zh-cn" ? "设置别名" : "Setalias" }}
                    </el-button>
                    <el-button type="primary" @click="setArea">
                      {{ i18n.language === "zh-cn" ? "设置区号" : "SetAreaCode" }}
                    </el-button>
                    <el-button type="primary" @click="groupNum">{{ i18n.fy.设置组号 }}</el-button>
                    <el-button type="primary" @click="allPropertie">{{ i18n.fy.全设备属性 }}</el-button>
                    <el-button type="primary" @click="itemPropertie" v-if="area == 100"> 单设备属性 </el-button>
                    <el-button type="primary" @click="moreOperate()">
                      {{ i18n.language === "zh-cn" ? "更多操作" : "MoreActions" }}
                      <el-icon class="el-icon--right"><arrow-down /></el-icon></el-button>
                  </span>
                </el-col>
              </el-row>
            </div>
          </div>
        </template>
        <template #table>
          <el-table ref="multipleTableRef" class="wiretab" :data="data.tableData" border v-loading="data.loading"
            :element-loading-text="i18n.fy.loading" @selection-change="handleSelectionChange" @select="selectClick"
            @row-click="handleRowClick" @sort-change="sort_change">
            <el-table-column type="selection" width="55" fixed :selectable="selected" />
            <el-table-column prop="macaddress" :label="i18n.fy.SerialNumber" width="70" align="center" fixed>
              <template #default="scope">
                {{ scope.$index + 1 + (data.queryForm.page - 1) * data.queryForm.limit }}
              </template>
            </el-table-column>
            <el-table-column prop="macaddress" :label="i18n.fy.MACAddress" width="150" fixed />
            <el-table-column prop="customName" :label="i18n.fy.DeviceAliases" :sortable="true" fixed width="150"
              :show-overflow-tooltip="true">
              <template #default="scope">
                <span v-if="scope.row.customName === '01'">CCO</span>
                <span v-else-if="scope.row.customName === '02'">STA</span>
                <span v-else-if="scope.row.customName === '03'">METER</span>
                <span v-else>
                  {{ scope.row.customName || "" }}
                </span>
              </template>
            </el-table-column>
            <el-table-column prop="deviceType" :label="i18n.fy.EquipmentName" :sortable="true" width="150" />
            <el-table-column prop="operatingStatus" :label="i18n.fy.DeviceStatus" :sortable="true" width="150">
              <template #default="scope">
                <span v-if="scope.row.operatingStatus === '01'" style="color: lawngreen">在线</span>
                <span v-else-if="scope.row.operatingStatus === '00'" style="color: #ddd">离线</span>
                <span v-else>{{ scope.row.operatingStatus }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="areaCode" :label="i18n.fy.EquipmentArea" width="150" sortable="custom">
            </el-table-column>
            <el-table-column prop="groupName" :label="i18n.fy.EquipmentGroupNumber" width="200">
              <template #header="scope">
                <div style="display: flex" class="selectName">
                  {{ i18n.fy.EquipmentGroupNumber }}
                  <select v-model="customName" placeholder="" @change="setCustomName()">
                    <option v-for="item in options" :value="item.v">
                      {{ item.group_name }}
                    </option>
                  </select>
                </div>
              </template>
              <template #default="scope">
                <span>
                  {{ scope.row.groupName }}
                </span>
              </template>
            </el-table-column>
            <el-table-column prop="luminance" :label="i18n.fy.CurrentBrightness" width="150"> </el-table-column>
            <el-table-column prop="triggerOpenLightNum" :label="i18n.fy.Someonebrightness" width="150">
            </el-table-column>
            <el-table-column prop="triggerFloodlightNum" :label="i18n.fy.Unmannedbrightness" width="150">
            </el-table-column>
            <el-table-column prop="darkenDelay" :label="i18n.fy.Delaytime" width="150"> </el-table-column>
            <el-table-column prop="colorTemperature" :label="i18n.fy.Currentchromaticity" width="150">
            </el-table-column>
            <el-table-column prop="hasTrigger" :label="i18n.fy.Sensingheadstatus" width="150"> </el-table-column>
            <el-table-column prop="sensorSensitivity" :label="i18n.fy.sensorSensitivity" width="150"> </el-table-column>
            <el-table-column prop="sceneNo" :label="'情景模式'" width="150">
              <template #default="scope">
                {{ scope.row.sceneNo }}
              </template>
            </el-table-column>
            <el-table-column prop="ratedPower" :label="i18n.fy.ratedPower" width="150"> </el-table-column>
            <el-table-column prop="energyDur" :label="i18n.fy.electricity + '(KWH)'" width="150">
              <template #default="scope">
                <span v-if="scope.row.energyDur != null"> {{ ((((scope.row.ratedPower * 1) / 1000) * scope.row.energyDur
        * 1) / 3600).toFixed(3) }}</span>
                <span v-if="scope.row.energyDur == null"> </span>
              </template>
            </el-table-column>
            <el-table-column prop="amp" :label="i18n.fy.power + '(KW)'" width="150">
              <template #default="scope">
                <span v-if="scope.row.amp != null"> {{ scope.row.amp / 100 }}</span>
                <span v-if="scope.row.amp == null"> </span>
              </template>
            </el-table-column>
            <el-table-column prop="watt" :label="i18n.fy.current + '(A)'" width="150">
              <template #default="scope">
                <span v-if="scope.row.watt != null">{{ scope.row.watt / 100 }}</span>
                <span v-if="scope.row.watt == null"> </span>
              </template>
            </el-table-column>
            <el-table-column prop="softwareVersion" :label="i18n.fy.Version" width="150" />
            <el-table-column prop="updateTime" :label="i18n.fy.updateTime" width="170"> </el-table-column>
          </el-table>
        </template>
        <template #pagination>
          <el-pagination @size-change="onChanSize" @current-change="onChanPage"
            v-model:current-page="data.queryForm.page" v-model:page-size="data.queryForm.limit" :total="data.total" />
        </template>
      </RightTableLayout>
    </template>
  </TreeTableLayout>
  <!-- 弹窗 -->
  <div id="slideDiv" style="display: none; padding: 20px; text-align: center">
    <div id="slideTest1"></div>
  </div>
  <div id="slideDiv2" style="display: none; padding: 20px; text-align: center">
    <div class="layui-form-item">
      <label class="layui-form-label">关灯值:</label>
      <div class="layui-input-block">
        <div id="slide1"></div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">开灯值:</label>
      <div class="layui-input-block">
        <div id="slide2"></div>
      </div>
    </div>
  </div>
  <div id="slideDiv3" class="slideDiv linev" style="display: none; padding: 20px; text-align: center">
    <div class="layui-form-item">
      <label class="layui-form-label">亮度调高时间:</label>
      <div class="layui-input-block">
        <div id="slide3"></div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">亮度调低时间:</label>
      <div class="layui-input-block">
        <div id="slide4"></div>
      </div>
    </div>
  </div>
  <div id="lightTestDiv5" style="display: none; padding: 20px; text-align: center">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <label class="layui-form-label">模式：</label>
        <div class="layui-input-block radiocont">
          <el-radio-group v-model="radio5" class="ml-4">
            <el-radio label="reportSetting">手动更新</el-radio>
            <el-radio label="reportSettingAck">自动更新12</el-radio>
          </el-radio-group>
        </div>
      </div>
    </form>
  </div>
  <div id="lightTestDiv" style="display: none; padding: 20px; text-align: center">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <label class="layui-form-label">开关值:</label>
        <div class="layui-input-block">
          <input type="radio" name="lTest" value="0" title="开" checked="" />
          <div class="layui-unselect layui-form-radio layui-form-radioed">
            <i class="layui-anim layui-icon"></i>
            <div>开</div>
          </div>
          <input type="radio" name="lTest" value="1" title="关" />
          <div class="layui-unselect layui-form-radio">
            <i class="layui-anim layui-icon"></i>
            <div>关</div>
          </div>
        </div>
      </div>
    </form>
  </div>
  <div id="lightNameDiv" style="display: none; padding: 20px; text-align: center">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <div class="layui-inline">
          <div class="lightNameDiv">
            <label class="layui-form-label">设备名称:</label>
            <div class="layui-input-inline">
              <input type="text" name="customName" id="customName" autocomplete="off" class="layui-input" />
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
  <div style="display: none; padding: 20px" id="groupNameDiv">
    <div class="layui-form-item">
      <div class="layui-form-item">
        <label class="layui-form-label">组名:</label>
        <div class="layui-input-block">
          <input type="text" name="groupName" id="groupName" lay-verify="required" autocomplete="off"
            class="layui-input" />
        </div>
      </div>
    </div>
  </div>
  <div id="lightNameDiv2" style="display: none; padding: 20px; text-align: center">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <div class="layui-inline">
          <div>
            <label class="layui-form-label">设备组号:</label>
            <div class="layui-input-inline">
              <input type="text" name="groupNum" id="groupNum" autocomplete="off" class="layui-input" />
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
  <div id="lightNameDiv2_3" style="display: none; padding: 20px; text-align: center">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <div class="layui-inline">
          <div>
            <label class="layui-form-label">设备组号:</label>
            <div class="layui-input-inline">
              <input type="text" name="groupNum" id="groupNum_3" autocomplete="off" class="layui-input" />
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
  <div id="lightNameDiv4" style="display: none; padding: 20px; text-align: center">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <div class="layui-inline">
          <div>
            <label class="layui-form-label">设备区号:</label>
            <div class="layui-input-inline">
              <input type="text" name="areaCode" id="areaCode" autocomplete="off" class="layui-input" />
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
  <div id="lightNameDiv4_3" style="display: none; padding: 20px; text-align: center">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <div class="layui-inline">
          <div>
            <label class="layui-form-label">设备区号:</label>
            <div class="layui-input-inline">
              <input type="text" name="areaCode" id="areaCode_3" autocomplete="off" class="layui-input" />
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
  <el-dialog class="dialogPermiss" style="background: #000" v-model="dialogTableVisible" title="设置区组号" width="85%"
    :before-close="handleClose" draggable>
    <div class="PermissionList">
      <div class="setArea3">
        <el-button type="primary" @click="setArea3">
          {{ i18n.language === "zh-cn" ? "设置区号" : "SetAreaCode" }}
        </el-button>
        <el-button type="primary" @click="groupNum3">
          {{ i18n.language === "zh-cn" ? "设置组号" : "SetGroupNumber" }}
        </el-button>
        <el-button type="primary" @click="ungroup3">
          {{ i18n.language === "zh-cn" ? "解除分组" : "Ungroup" }}
        </el-button>
      </div>
      <el-table ref="multipleTableRef_3" :scrollbar-always-on="true" style="width: 100%" class="wiretab"
        :data="gridData" border :element-loading-text="i18n.fy.loading" @selection-change="handleSelectionChange_3"
        @select="selectClick_3" @row-click="handleRowClick_3" @sort-change="sort_change2">
        <el-table-column type="selection" width="55" fixed :selectable="selected_3" />
        <el-table-column prop="macaddress" :label="i18n.fy.SerialNumber" width="70" align="center" fixed>
          <template #default="scope">
            {{ scope.$index }}
          </template>
        </el-table-column>
        <el-table-column prop="macaddress" :label="i18n.fy.MACAddress" width="150" fixed />
        <el-table-column prop="customName" :label="i18n.fy.DeviceAliases" :sortable="true" fixed width="150"
          :show-overflow-tooltip="true">
          <template #default="scope">
            <span v-if="scope.row.customName === '01'">CCO</span>
            <span v-else-if="scope.row.customName === '02'">STA</span>
            <span v-else-if="scope.row.customName === '03'">METER</span>
            <span v-else>
              {{ scope.row.customName || "" }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="deviceType" :label="i18n.fy.EquipmentName" :sortable="true" width="150" />
        <el-table-column prop="operatingStatus" :label="i18n.fy.DeviceStatus" :sortable="true" width="150">
          <template #default="scope">
            <span v-if="scope.row.operatingStatus === '01'" style="color: lawngreen">在线</span>
            <span v-else-if="scope.row.operatingStatus === '00'" style="color: #ddd">离线</span>
            <span v-else>{{ scope.row.operatingStatus }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="areaCode" :label="i18n.fy.EquipmentArea" width="150" sortable="custom">
        </el-table-column>
        <el-table-column prop="groupName" :label="i18n.fy.EquipmentGroupNumber" width="200">
          <template #header="scope">
            <div style="display: flex" class="selectName">
              {{ i18n.fy.EquipmentGroupNumber }}
            </div>
          </template>
          <template #default="scope">
            <span>
              {{ scope.row.groupName }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="luminance" :label="i18n.fy.CurrentBrightness" width="120"> </el-table-column>
        <el-table-column prop="triggerOpenLightNum" :label="i18n.fy.Someonebrightness" width="120"> </el-table-column>
        <el-table-column prop="triggerFloodlightNum" :label="i18n.fy.Unmannedbrightness" width="120"> </el-table-column>
        <el-table-column prop="darkenDelay" :label="i18n.fy.Delaytime" width="120"> </el-table-column>
        <el-table-column prop="colorTemperature" :label="i18n.fy.Currentchromaticity" width="120"> </el-table-column>
        <el-table-column prop="hasTrigger" :label="i18n.fy.Sensingheadstatus" width="120"> </el-table-column>
        <el-table-column prop="sensorSensitivity" :label="i18n.fy.sensorSensitivity" width="120"> </el-table-column>
        <el-table-column prop="sceneNo" :label="'情景模式'" width="120">
          <template #default="scope">
            {{ scope.row.sceneNo }}
          </template>
        </el-table-column>
        <el-table-column prop="ratedPower" :label="i18n.fy.ratedPower" width="120"> </el-table-column>
        <el-table-column prop="energyDur" :label="i18n.fy.electricity + '(KWH)'" width="120">
          <template #default="scope">
            <span v-if="scope.row.energyDur != null"> {{ ((((scope.row.ratedPower * 1) / 1000) * scope.row.energyDur *
        1) / 3600).toFixed(3) }}</span>
            <span v-if="scope.row.energyDur == null"> </span>
          </template>
        </el-table-column>
        <el-table-column prop="amp" :label="i18n.fy.power + '(KW)'" width="120">
          <template #default="scope">
            <span v-if="scope.row.amp != null"> {{ scope.row.amp / 100 }}</span>
            <span v-if="scope.row.amp == null"> </span>
          </template>
        </el-table-column>
        <el-table-column prop="watt" :label="i18n.fy.current + '(A)'" width="120">
          <template #default="scope">
            <span v-if="scope.row.watt != null">{{ scope.row.watt / 100 }}</span>
            <span v-if="scope.row.watt == null"> </span>
          </template>
        </el-table-column>
        <el-table-column prop="softwareVersion" :label="i18n.fy.Version" width="120" />
        <el-table-column prop="updateTime" :label="i18n.fy.updateTime" width="170"> </el-table-column>
      </el-table>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogTableVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogTableVisible = false"> 确定 </el-button>
      </span>
    </template>
  </el-dialog>
  <el-dialog top="60px" class="Actions" v-model="dialogVisible" draggable
    :title="i18n.language === 'zh-cn' ? '更多操作' : 'More Actions'" :width="i18n.language === 'zh-cn' ? '48%' : '50%'">
    <div>
      <div class="top">
        <el-row>
          <el-col :span="4">
            <el-select clearable v-model="area" class="m-2" placeholder="">
              <el-option v-for="item in darrOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-col>
          <el-col :span="5" v-if="area != ''">
            <span>网关</span>
            <el-select clearable v-model="gateway" class="m-2" placeholder="">
              <el-option :label="'全部网关'" :value="''" />
              <el-option v-for="item in gatewayList" :key="item.id" :label="item.nickName" :value="item.id" />
            </el-select>
          </el-col>
          <el-col :span="4" v-if="area != ''">
            <span>区</span>
            <el-select clearable @change="changeAistrict()" v-model="district"
              :placeholder="i18n.language === 'zh-cn' ? '区' : 'distinguish'" style="width: 170px">
              <el-option v-for="item in deviceAreaAllList" :value="item.area_code">
                {{ item.area_code }}
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="4" v-if="area != '' && area == '300'">
            <span>标签</span>
            <el-input v-model="tag" placeholder="" />
          </el-col>
          <el-col :span="5" v-if="area != '' && area == '200'">
            <span>组</span>
            <el-select clearable @change="changeGroup()" v-model="group" placeholder="" style="width: 150px">
              <el-option v-show="item.group_name != '全部'" v-for="item in options" :value="item.group_name">
                {{ item.group_name }}
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="4" v-if="area != '' && area == '100'">
            <span>号</span>
            <el-input v-model="num" placeholder="" />
          </el-col>
          <el-col :span="5" v-if="area != ''"> <span>网络密码</span><el-input v-model="identity" placeholder="" /> </el-col>
        </el-row>
      </div>
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
        <el-tab-pane :label="i18n.language === 'zh-cn' ? '灯具设置' : 'Lamp settings'" name="first">
          <el-tabs :tab-position="'left'" type="border-card" style="height: 700px" class="demo-tabs">
            <el-tab-pane :label="i18n.language === 'zh-cn' ? '基本设置' : 'Basic Settings'">
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "亮灯模式" : "Lighting mode" }}
                </el-col>
                <el-col :span="14">
                  <el-radio-group v-model="radio1">
                    <el-radio-button :label="i18n.fy.常亮" />
                    <el-radio-button :label="i18n.fy.常灭" />
                    <el-radio-button :label="i18n.fy.感应" />
                  </el-radio-group>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setLightMode', radio1)">
                    {{ i18n.fy.sending }}
                  </el-button>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "有人亮度" : "Someones brightness" }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue" /><span>{{ sliderValue }}%</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setHighBright', sliderValue)">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "无人亮度" : "Unmanned brightness" }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue2" /><span>{{ sliderValue2 }}%</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setStandbyBright', sliderValue2)">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "色温" : "Color temperature" }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue3" /><span>{{ sliderValue3 }}%</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setCctBright', sliderValue3)">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "感应模式" : "Sensing mode" }}
                </el-col>
                <el-col :span="14">
                  <el-radio-group v-model="radio2">
                    <el-radio-button :label="i18n.language === 'zh-cn' ? '一段' : 'aSectionOf'" />
                    <el-radio-button :label="i18n.language === 'zh-cn' ? '二段' : 'Section2'" />
                  </el-radio-group>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setDelayMode', radio2)">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "一段延时" : "A period of delay" }}
                </el-col>
                <el-col :span="14">
                  <el-select v-model="oneDate" class="m-2" placeholder="">
                    <el-option v-for="item in dateOptions" :key="item.value" :label="item.label" :value="item.value" />
                  </el-select>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setDelayTime', oneDate)">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "二段延时" : "Two stage delay" }}
                </el-col>
                <el-col :span="14">
                  <el-select v-model="one2Date" class="m-2" placeholder="">
                    <el-option v-for="item in dateOptions" :key="item.value" :label="item.label" :value="item.value" />
                  </el-select>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setDelayTime2', one2Date)">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "恒照度模式" : "Constant illumination mode" }}
                </el-col>
                <el-col :span="14">
                  <el-radio-group v-model="radio3">
                    <el-radio-button :label="i18n.language === 'zh-cn' ? '无效' : 'invalid'" />
                    <el-radio-button :label="i18n.language === 'zh-cn' ? '自控' : 'automaticControl'" />
                    <el-radio-button :label="i18n.language === 'zh-cn' ? '被控' : 'controlled'" />
                  </el-radio-group>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setAlsMode', radio3)">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "应用到场景" : "Constant illumination mode" }}
                </el-col>
                <el-col :span="14">
                  <el-radio-group v-model="mode_0">
                    <el-radio-button label="场景1" />
                    <el-radio-button label="场景2" />
                    <el-radio-button label="场景3" />
                    <el-radio-button label="场景4" />
                    <el-radio-button label="场景5" />
                    <el-radio-button label="场景6" />
                  </el-radio-group>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="setScen()">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane :label="i18n.language === 'zh-cn' ? '传感器设置' : 'Sensor settings'">
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "传感器开关" : "Sensor switch" }}
                </el-col>
                <el-col :span="14">
                  <el-switch v-model="switchValue" style="--el-switch-on-color: #217093; --el-switch-off-color: #e4e7ed"
                    :active-text="i18n.fy.开" :inactive-text="i18n.fy.关" inline-prompt />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send(switchValue ? 'ssrOff' : 'ssrOn', '')">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "网组开关" : "Network group switch" }}
                </el-col>
                <el-col :span="14">
                  <el-switch v-model="switchValue2"
                    style="--el-switch-on-color: #217093; --el-switch-off-color: #e4e7ed" :active-text="i18n.fy.开"
                    :inactive-text="i18n.fy.关" inline-prompt />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send(switchValue2 ? 'netOff' : 'netOn', '')">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "触发间隔" : "trigger interval" }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue4" :max="9" /><span>{{ sliderValue4 }}秒</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setSensorInterval', sliderValue4)">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane :label="i18n.language === 'zh-cn' ? '调光设置' : 'Dimming settings'">
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "亮灯速度" : "Illumination speed" }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue5" :max="9" /><span>{{ sliderValue5 }}秒</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setBrightRiseTime', sliderValue5)">发送</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "灭灯速度" : "Light off speed" }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue6" :max="9" /><span>{{ sliderValue6 }}秒</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setBrightFallTime', sliderValue6)">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "色温调高速度" : "Color temperature adjustment speed" }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue7" :max="9" /><span>{{ sliderValue7 }}秒</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setCctRiseTime', sliderValue7)">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "色温降低速度" : "Color temperature reduction speed" }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue8" :max="9" /><span>{{ sliderValue8 }}秒</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setCctFallTime', sliderValue8)">
                    {{ i18n.fy.sending }}
                  </el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane :label="i18n.language === 'zh-cn' ? '遥控器设置' : 'Remote control settings'">
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "红外遥控" : "infrared remote control" }}
                </el-col>
                <el-col :span="14">
                  <el-switch v-model="switchValue3"
                    style="--el-switch-on-color: #217093; --el-switch-off-color: #e4e7ed" :active-text="i18n.fy.开"
                    :inactive-text="i18n.fy.关" inline-prompt />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send(switchValue3 ? 'ircOff' : 'ircOn', '')">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane :label="i18n.language === 'zh-cn' ? '恒照度' : 'Constant illuminance'">
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "设置照度值" : "Set illuminance value" }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input1" placeholder="目标照度值[0~9000]" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setAlsLux', input1)">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "发射开关" : "Launch switch" }}
                </el-col>
                <el-col :span="14">
                  <el-switch v-model="switchValue4"
                    style="--el-switch-on-color: #217093; --el-switch-off-color: #e4e7ed" :active-text="i18n.fy.开"
                    :inactive-text="i18n.fy.关" inline-prompt />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send(switchValue4 ? 'alsSyncDisable' : 'alsSyncEnable', '')">
                    {{ i18n.fy.sending }}
                  </el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.fy.发射间隔 }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue9" :max="9" /><span>{{ sliderValue9 }}秒</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setAlsInterval', sliderValue9)">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="6">
                  <div class="Naming">{{ i18n.fy.ntcis }}</div>
                </el-col>
                <el-col :span="12">
                  <el-input v-model="input2" placeholder="当前照度昵称" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setAlsNotice', input2)">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane :label="i18n.fy.网络设置">
              <el-row>
                <el-col :span="4">
                  {{ i18n.fy.组跳数 }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue10" :max="9" /><span>{{ sliderValue10 + i18n.fy.次 }}</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setGroupTtl', sliderValue10)">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.fy.网跳数 }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue11" :max="9" /><span>{{ sliderValue11 + i18n.fy.次 }}</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setNetTtl', sliderValue11)">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.fy.重发次数 }}
                </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue12" :max="9" /><span>{{ sliderValue12 + i18n.fy.次 }}</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setTxTimes', sliderValue12)">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.fy.转发开关 }}
                </el-col>
                <el-col :span="14">
                  <el-switch v-model="switchValue5"
                    style="--el-switch-on-color: #217093; --el-switch-off-color: #e4e7ed" :active-text="i18n.fy.开"
                    :inactive-text="i18n.fy.关" inline-prompt />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send(switchValue5 ? 'rlyOff' : 'rlyOn', '')">
                    {{ i18n.fy.sending }}
                  </el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>
        <el-tab-pane :label="i18n.fy.设备编号" name="second">
          <el-tabs :tab-position="'left'" type="border-card" style="height: 700px" class="demo-tabs">
            <el-tab-pane :label="i18n.fy.编号设置">
              <el-row>
                <el-col :span="4">
                  {{ i18n.fy.修改 + i18n.fy.区 }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input3" :placeholder="i18n.fy.请输入 + i18n.fy.新 + i18n.fy.区" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setAreaAddress', input3)"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.fy.修改 + i18n.fy.组 }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input4" :placeholder="i18n.fy.请输入 + i18n.fy.新 + i18n.fy.组" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setClusterAddress', input4)"> {{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.fy.修改 + i18n.fy.号 }}
                </el-col>
                <el-col :span="14">
                  <div style="display: flex">
                    <el-input v-model="input5"
                      :placeholder="i18n.language === 'zh-cn' ? '请输入UUID' : 'Please enter UUID'"
                      style="margin-right: 10px" />
                    <el-input v-model="input6"
                      :placeholder="i18n.language === 'zh-cn' ? '请输入新号' : 'Please enter a new number'" />
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setNumberAddress', input5 + '_' + input6)"> {{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "设置标签" : "Set label" }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input7"
                    :placeholder="i18n.language === 'zh-cn' ? '请输入新标签' : 'Please enter a new label'" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setLabel', input7)"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "删除标签" : "delete label" }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input8"
                    :placeholder="i18n.language === 'zh-cn' ? '请输入标签名' : 'Please enter a label name'" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('deleteLabel', input8)"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "清空标签" : "Clear label" }}
                </el-col>
                <el-col :span="14"> </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('clearLabel', '')"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "设置邻组通知" : "Set Neighbor Group Notification" }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input9"
                    :placeholder="i18n.language === 'zh-cn' ? '请输入邻组组号' : 'Please enter the neighboring group number'" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setNeighbour', input9)"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "删除邻组通知" : "Delete adjacent group notification" }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input10"
                    :placeholder="i18n.language === 'zh-cn' ? '请输入邻组组号' : 'Please enter the neighboring group number'" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('deleteNeighbour', '')"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "清空邻组通知" : "Clear adjacent group notifications" }}
                </el-col>
                <el-col :span="14"> </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('clearNeighbour', '')"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane :label="i18n.language === 'zh-cn' ? '设备关联' : 'Device Association'">
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "设备命名" : "Device Naming" }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input11"
                    :placeholder="i18n.language === 'zh-cn' ? '请输入设备名称' : 'Please enter a device name'" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setNickName', input11)"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "关联设备" : "Associated devices" }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input12"
                    :placeholder="i18n.language === 'zh-cn' ? '请输入设备名称' : 'Please enter a device name'" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('bind', input12)"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "解除关联" : "disassociation" }}
                </el-col>
                <el-col :span="14">
                  <el-input v-model="input13"
                    :placeholder="i18n.language === 'zh-cn' ? '请输入设备名称' : 'Please enter a device name'" />
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('relieve', input13)"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>
        <el-tab-pane :label="i18n.language === 'zh-cn' ? '情景模式' : 'profile'" name="third">
          <el-tabs :tab-position="'left'" type="border-card" style="height: 700px" class="demo-tabs">
            <el-tab-pane :label="i18n.language === 'zh-cn' ? '常规情景' : 'Conventional scenarios'">
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "读取情景模式" : "Read profile" }}
                </el-col>
                <el-col :span="14"> </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('readScene', '1')">
                    {{ i18n.fy.sending }}
                  </el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "切换情景模式" : "Switch Profile" }}
                </el-col>
                <el-col :span="14">
                  <el-select v-model="scene" class="m-2"
                    :placeholder="i18n.language === 'zh-cn' ? '请选择情景模式' : 'Please select a profile'">
                    <el-option v-for="item in sceneOptions" :key="item.value" :label="item.label" :value="item.value" />
                  </el-select>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('callScene', scene)"> {{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <p style="color: rgb(217, 150, 0); font-size: 14px">
                    {{ i18n.fy.rcbatslgze }}
                  </p>
                </el-col>
              </el-row>
            </el-tab-pane>
            <!-- 2024年4月26日15:30:25 -->
            <el-tab-pane :label="i18n.language === 'zh-cn' ? '定时情景' : 'Timed scenario'" v-loading="dsLoading">
              <el-row v-show="sceneVisible">
                <el-col :span="4">
                  {{ i18n.language === "zh-cn" ? "定时情景列表" : "Timed Scenario List" }}
                </el-col>
                <el-col :span="20" style="text-align: right">
                  <el-button type="primary" @click="addScene()">
                    {{ i18n.language === "zh-cn" ? "新增定时情景" : "Add timed scenarios" }}
                  </el-button>
                </el-col>
              </el-row>
              <el-row v-show="sceneVisible" style="border-bottom: 0">
                <el-col :span="24">
                  <div>
                    <el-table :data="sceneTableData" style="height: 450px" class="sceneTableData">
                      <el-table-column prop="ruleTitle" :label="i18n.fy.任务名称" />
                      <el-table-column prop="startTime" :label="i18n.fy.执行时间" width="180">
                        <template #default="scope">
                          <div v-html="showTime(scope.row)"></div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="name" :label="i18n.fy.调用情景" width="140">
                        <template #default="scope">
                          {{ showScope(scope.row) }}
                        </template>
                      </el-table-column>
                      <el-table-column prop="name" :label="i18n.language === 'zh-cn' ? '灯组' : 'Lamp group'">
                        <template #default="scope">
                          <p class="operateInfo" v-for="(item, i) in showOper(scope.row.operateInfo)">
                            {{ item.area }}区
                            <span v-if="item.code != '400'">{{ item.address }}</span>
                            <span v-if="item.code == '200'">组</span>
                            <span v-if="item.code == '300'">标签</span>
                            <span v-if="item.code == '100' || item.code == '10'">号</span>
                          </p>
                        </template>
                      </el-table-column>
                      <el-table-column prop="name" :label="i18n.fy.operation" align="center" width="190">
                        <template #default="scope">
                          <el-button link type="primary" class="profile-btn-color-l" @click="testScen(scope.row)"
                            v-if="enable">
                            {{ i18n.fy.测试 }}
                          </el-button>
                          <el-button link type="primary" class="profile-btn-color-h" @click="editScen(scope.row)">
                            {{ i18n.fy.编辑 }}
                          </el-button>
                          <el-button link type="primary" style="color: #fff" @click="changeEnableState(scope.row, 1)"
                            v-if="scope.row.enableState == '0'">
                            {{ i18n.fy.启用 }}
                          </el-button>
                          <el-button link type="danger" @click="changeEnableState(scope.row, 0)"
                            v-if="scope.row.enableState == '1'">
                            {{ i18n.fy.停用 }}
                          </el-button>
                          <el-button link type="danger" @click="delScen(scope.row)">
                            {{ i18n.fy.删除 }}
                          </el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </el-col>
              </el-row>
              <el-row v-show="!sceneVisible">
                <div class="sceneVisible">
                  <el-col :span="24">
                    <div class="newName">
                      <span>任务名称</span>
                      <el-input v-model="scenModel.data.ruleTitle" placeholder="请输入" style="width: 220px" />
                    </div>
                  </el-col>
                  <el-col :span="24">
                    <div class="newName">
                      <span style="color:red;">{{ i18n.fy.执行模式 }}</span>
                      <el-select @change="(val) => changeWorkDay(val)" style="width: 220px" multiple
                        v-model="scenModel.data.chooseWorkDay" class="m-2" placeholder="请选择情景模式">
                        <el-option v-for="(item, i) in carryOptions" :key="item.value" :label="item.label"
                          :value="item.value" />
                      </el-select>
                      <span>执行时间</span>
                      <el-time-picker style="width: 220px" format="HH:mm" data-format="HH:mm" value-format="HH:mm"
                        v-model="scenModel.data.startTime" placeholder="任意时间点" />
                    </div>
                  </el-col>
                  <el-col :span="24">
                    <div class="newName">
                      <span>{{ i18n.fy.调用情景 }}</span>
                      <el-select style="width: 220px" v-model="transferScene" class="m-2" placeholder=""
                        @change="changeTransferScene">
                        <el-option v-for="item in sceneOptions" :key="item.value" :label="item.label"
                          :value="item.value" />
                      </el-select>
                    </div>
                  </el-col>
                  <el-col :span="24">
                    <div class="newName">
                      <span>操控灯组</span>
                    </div>
                  </el-col>
                  <el-col :span="24">
                    <p class="altconp">
                      <span class="altcon" v-for="(item, i) in scenModel.data.operateInfoObj" @click="deleteTag(i)">
                        {{ item.area }}区
                        <span v-if="item.code != '400'">{{ item.address }}</span>
                        <span v-if="item.code == '200'">组</span>
                        <span v-if="item.code == '300'">标签</span>
                        <span v-if="item.code == '100' || item.code == '10'">号</span>
                      </span>
                      <el-button style="margin-left: 5px" type="primary" @click="addingLamp()"
                        :disabled="wmStore.deviceNumberList.leng > 0">{{ i18n.fy.新增灯具 }}</el-button>
                    </p>
                  </el-col>
                  <el-col :span="24" style="text-align: center">
                    <el-button type="primary" @click="submitScen()">{{ i18n.fy.提交定时情景 }}</el-button>
                    <el-button type="" @click="sceneVisible = true">返回</el-button>
                  </el-col>
                </div>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>
        <el-tab-pane :label="i18n.language === 'zh-cn' ? '上报设置' : 'profile'" name="third2">
          <el-tabs :tab-position="'left'" type="border-card" style="height: 700px" class="demo-tabs">
            <el-tab-pane label="电量上报">
              <el-row>
                <el-col :span="4"> 开启上报 </el-col>
                <el-col :span="14">
                  <div class="sliderbox tipsBox">提示：开启电量上报，间隔是半小时</div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('reportConsumption')">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4"> 时间间隔 </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue13" :max="128" :min="1" /><span
                      style="display: inline-block; width: 100px">{{ sliderValue13 }}分钟</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setConsumptioninterval', sliderValue13)">
                    {{ i18n.fy.sending }}
                  </el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4"> 关闭上报 </el-col>
                <el-col :span="14">
                  <div class="sliderbox"></div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('reportConsumptionStop')">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4"> 只上报三次 </el-col>
                <el-col :span="14">
                  <div class="sliderbox tipsBox">提示：只上报三次，每次间隔10秒，上报完成自动结束</div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('reportConsumptionAck')">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="照明参数上报">
              <el-row>
                <el-col :span="4"> 开启上报 </el-col>
                <el-col :span="14">
                  <div class="sliderbox tipsBox">提示：开启照明参数上报，间隔是半小时</div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('reportSetting')">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4"> 时间间隔 </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue14" :max="128" :min="1" /><span
                      style="display: inline-block; width: 100px">{{ sliderValue14 }}分钟</span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('setSettinginterval', sliderValue14)">{{ i18n.fy.sending
                    }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4"> 关闭上报 </el-col>
                <el-col :span="14">
                  <div class="sliderbox"></div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('reportSettingStop')">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4"> 只上报三次 </el-col>
                <el-col :span="14">
                  <div class="sliderbox tipsBox">提示：只上报三次，每次间隔10秒，上报完成自动结束</div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('reportSettingAck')">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>
        <el-tab-pane :label="i18n.language === 'zh-cn' ? '网关设置' : 'profile'" name="third3">
          <el-tabs :tab-position="'left'" type="border-card" style="height: 700px" class="demo-tabs">
            <el-tab-pane label="网关其他操作">
              <el-row>
                <el-col :span="4"> 定时重启 </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-time-picker v-model="value17" is-range range-separator="至" format="HH:mm" value-format="HH:mm"
                      start-placeholder="开始时间" end-placeholder="结束时间" />
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('rebootSetting', value17[0] + '-' + value17[1])">
                    {{ i18n.fy.sending }}
                  </el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4"> 直接重启 </el-col>
                <el-col :span="14">
                  <div class="sliderbox">
                    <el-slider v-model="sliderValue17" :max="60" :min="10" /><span
                      style="display: inline-block; width: 168px"> 重启前等待的{{ sliderValue17 }}秒 </span>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('reboot', sliderValue17)">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4"> 升级 </el-col>
                <el-col :span="14">
                  <div class="sliderbox tipsBox">提示：网关支持远程更新，网关在线的情况下对网关下发upgrade指令，网关收到指令后会自动到服务器查询最新的发布版本，并自动下载更新，
                    更新成功之后网关会自行重启</div>
                </el-col>
                <el-col :span="4" style="text-align: right">
                  <el-button type="primary" @click="send('upgrade')">{{ i18n.fy.sending }}</el-button>
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>
      </el-tabs>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">关闭</el-button>
      </span>
    </template>
  </el-dialog>
  <el-dialog v-model="lampVisible" draggable :title="`${i18n.fy.新增灯具} - (当前网关：${wmStore.treeGateway.gatewayName})`"
    width="40%" :close-on-click-modal="false">
    <AddLamp ref="addLampRef" v-if="lampVisible" :available="scenModel.data.operateInfoObj"></AddLamp>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="confirmAddLamp">{{ i18n.fy.confirm }}</el-button>
        <el-button @click="lampVisible = false"> {{ i18n.fy.cancel }} </el-button>
      </span>
    </template>
  </el-dialog>
  <el-dialog :close-on-click-modal="false" v-model="dialogVisible2" draggable
    :title="i18n.language === 'zh-cn' ? '扫描添灯' : 'Scan and add light'" width="50%" class="newAdd"
    style="background: #000" @close="closeDialog" top="30px">
    <div style="padding-bottom: 30px">
      <div>
        <div class="top tops" style="margin-top: -20px">
          <el-row>
            <el-col :span="24">
              <span :span="4">
                <el-select style="width: 120px; margin-left: -6px" v-model="gateway" class="m-2" placeholder="">
                  <el-option :label="i18n.fy.全部网关" :value="''" />
                  <el-option v-for="item in gatewayList" :key="item.id" :label="item.nickName" :value="item.id" />
                </el-select>
              </span>
              <span :span="3">
                <el-input style="width: 100px" v-model="district" :placeholder="i18n.fy.区" />
              </span>
              <span :span="3" style="display: none">
                <el-input style="width: 100px" v-model="group" placeholder="组" />
              </span>
              <span :span="3" style="display: none">
                <el-input style="width: 100px" v-model="num" placeholder="号" />
              </span>
              <span :span="4" style="display: none">
                <el-input style="width: 120px" v-model="identity" placeholder="网络密码" />
              </span>
              <span :span="4">
                <el-button type="primary" @mouseover="mouLight" @mouseout="outLinght"
                  :class="{ searchFlag: searchFlag }" @click="searchLight()">
                  {{ searchHtml }}
                  <el-icon v-show="iconFlag">
                    <Loading class="loa" />
                  </el-icon>
                </el-button>
              </span>
              <el-button class="handLight" type="primary" @click="handLight()"> 手动加灯 </el-button>
              <span>
                <el-switch v-model="switchFlag" size="large" :loading="addLoading"
                  style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" active-text="自动加灯已开启"
                  inactive-text="自动加灯已关闭" inline-prompt :before-change="showPopover" />
              </span>
            </el-col>
          </el-row>
        </div>
      </div>
      <el-table :data="data.tableData2" height="50vh" style="width: 100%" class="newAddTab"
        @selection-change="handleSelectionChange2">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="macaddress" label="MAC地址" width="180">
          <template #default="scope">
            <span v-if="scope.row.flag == undefined || scope.row.flag == false">
              {{ scope.row.macaddress }}
            </span>
            <span v-else>
              <el-input style="width: 120px" v-model="scope.row.macaddress" placeholder="MAC地址" />
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="areaCode" label="区" :sortable="true">
          <template #default="scope">
            <span v-if="scope.row.flag == undefined || scope.row.flag == false">
              {{ scope.row.areaCode }}
            </span>
            <span v-else>
              <el-input v-model="scope.row.areaCode" placeholder="区" />
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="groupName" label="组" :sortable="true">
          <template #default="scope">
            <span v-if="scope.row.flag == undefined || scope.row.flag == false">
              {{ scope.row.groupName }}
            </span>
            <span v-else>
              <el-input v-model="scope.row.groupName" placeholder="组" />
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="deviceIndex" label="号" :sortable="true">
          <template #default="scope">
            <span v-if="scope.row.flag == undefined || scope.row.flag == false">
              {{ scope.row.deviceIndex }}
            </span>
            <span v-else>
              <el-input v-model="scope.row.deviceIndex" placeholder="号" />
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="deviceType" label="类型">
          <template #default="scope">
            <span v-if="scope.row.flag == undefined || scope.row.flag == false">
              {{ scope.row.deviceType }}
            </span>
            <span v-else>
              <el-input v-model="scope.row.deviceType" placeholder="类型" />
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="updateTime" label="更新时间" width="180" :sortable="true">
          <template #default="scope">
            <span v-if="scope.row.flag == undefined || scope.row.flag == false">
              {{ scope.row.updateTime }}
            </span>
            <span v-else>
              <el-date-picker style="width: 120px" v-model="scope.row.updateTime" format="YYYY-MM-DD HH:mm:ss"
                type="datetime" placeholder="更新时间" />
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="option" label="操作" width="120">
          <template #default="scope">
            <el-button type="primary" size="small" @click="start(scope.row)">闪一闪</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="operateScan('scan')" :loading="data.loading2">
          {{ data.loading2 ? "正在扫描中...." : "扫描设备" }}
        </el-button>
        <el-button type="primary" @click="operateStop()">停止扫描</el-button>
        <el-button type="primary" @click="enterAdd()">确认新增</el-button>
        <el-button @click="close"> 关闭 </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
defineOptions({ name: "SetDevice" });
import { i18nStore } from "@/pinia/i18n";
const i18n = i18nStore();
import { wirelessManageStore } from "@/pinia/wirelessManage";
const wmStore = wirelessManageStore();
import { workbenchScreenStore } from "@/pinia/workbenchScreen";
const wsStore = workbenchScreenStore();
import RightTableLayout from "@/views/workbench/components/RightTableLayout.vue";
import TreeTableLayout from "@/views/workbench/components/TreeTableLayout.vue";
import Tree from "@/components/tree.vue";

import { getAllDeviceTimingList, testTimingInterface, upStateTimingInterface, queryOperationDeviceAllList, getDeviceAreaAllList, getDeviceAliasAllList, upMeshTimingRule, getAutoLightData, upAutoAddLight } from "@/api/wirelessmanageApi";
import AddLamp from "@/views/workbench/wirelessManage/AddLamp.vue";
const addLampRef = ref(null);

const {
  appContext: {
    config: { globalProperties },
  },
} = getCurrentInstance();
let $httpUrl = globalProperties.$httpUrl;

// 在组件挂载之前执行
onBeforeMount(() => {
  console.log("setWirelessdevice->组件挂载前->", sceneOptions);
  let arr = [];
  for (let index = 1; index < 13; index++) {
    let obj = { value: index, label: `场景${index}` };
    arr.push(obj);
  }
  sceneOptions.value = arr;
});

let columns = reactive({
  deviceTitle: {
    label: "设备名称", //列名称
    queryValue: "",
  },
});
const dsLoading = ref(false);
let addLoading = ref(false);
let data = reactive({
  queryForm: {
    page: 1,
    limit: 100,
  },
  tableData: [],
  tableData2: [],
  total: 0,
  dialog: false,
  form: {},
  rules: {
    name: [{ required: true, message: "请输入姓名", trigger: "change" }],
    role: [{ required: true, message: "请选择岗位", trigger: "change" }],
  },
});
let pid = ref("");
let queryParams = {};
const doQuery = async (params) => {
  customName.value = "全部";
  queryParams = params;
  pid.value = params.deviceFid;
  gateway.value = pid.value;
  getDeviceAliasAllListFun();
  getDeviceAreaAllListFun();
  getList(params);
  $.get($httpUrl + "/userLightNum/queryUserLightNum", { deviceFid: pid.value }, function (res) {
    if (res.data != null) {
      lightOnNum = res.data.lightOnNum;
      lightOffNum = res.data.lightOffNum;
    } else {
      lightOnNum = 40;
      lightOffNum = 0;
    }
  });
  let id = wmStore.treeProject.productId;
  if (id) {
    const res = await getAutoLightData(id);
    if (res.code === 200) {
      switchFlag.value = res.data;
    }
  }
};

const showPopover = async () => {
  let id = wmStore.treeProject.productId;
  if (id) {
    let params = { deviceFid: id, flag: !switchFlag.value };
    addLoading.value = true;
    const res = await upAutoAddLight(params);
    addLoading.value = false;
    if (res.code === 200) {
      switchFlag.value = res.data;
      ElMessage.success(res.data ? "开启成功" : "关闭" + res.message);
    } else {
      if (res.code === 903) {
        ElMessage.error(res.message);
      } else {
        ElMessage.error("自动加灯加灯发送失败");
      }
    }
  }
};

let gatewayList = ref([]);
const getGateway = (params) => {
  if (params == undefined) {
    return false;
  }
  gatewayList.value = params;
  gatewayList.value = gatewayList.value.sort((a, b) => {
    return a.id - b.id;
  });
  wmStore.setGatewayList(gatewayList.value);
};
const activeName = ref("first");
const handleClick = (tab, event) => { };
const hex2int = (hex) => {
  if (hex == null || hex == "") {
    return;
  }
  var len = hex.length,
    a = new Array(len),
    code;
  for (var i = 0; i < len; i++) {
    code = hex.charCodeAt(i);
    if (48 <= code && code < 58) {
      code -= 48;
    } else {
      code = (code & 0xdf) - 65 + 10;
    }
    a[i] = code;
  }

  return a.reduce(function (acc, c) {
    acc = 16 * acc + c;
    return acc;
  }, 0);
};

const reQueryForm = () => {
  // 重置查询表单
  data.queryForm = {
    page: 1,
    limit: 100,
  };
};
const multipleTableRef = ref();
const multipleTableRef_3 = ref();
const multipleSelection = ref([]);
const multipleSelection2 = ref([]);
const multipleSelection3 = ref([]);
const multipleSelection_3 = ref([]);
const toggleSelection = (rows) => {
  if (rows) {
    rows.forEach((row) => {
      // TODO: improvement typing when refactor table
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-expect-error
      multipleTableRef.value.toggleRowSelection(row, undefined);
    });
  } else {
    multipleTableRef.value.clearSelection();
  }
};
const selected = (row, index) => {
  if (area.value == 100) {
    return true; //不可勾选
  } else {
    return false;
  }
};
const selected_3 = (row, index) => {
  return true;
};
// 控制单选——table选择项发生变化时
const selectClick = (selection, row) => {
  return false;
};
const compare = (property, order) => {
  return function (a, b) {
    if (order == "descending") {
      return b[property] - a[property];
    } else if (order == "ascending") {
      return a[property] - b[property];
    } else {
      return 0;
    }
  };
};
let recordsOld = [];
const sort_change = (column) => {
  // console.log(recordsOld);
  let arr = JSON.parse(JSON.stringify(recordsOld));
  if (column.order != null) {
    arr = arr.sort(compare(column.prop, column.order));
  } else {
    arr = groupAndSort("groupNameLabel", "areaCodeLabel", arr);
    arr = arr.sort(createComprisonFunction("areaCodeLabel"));
  }
  data.queryForm.page = 1;
  data.tableData = arr.slice((data.queryForm.page - 1) * data.queryForm.limit, data.queryForm.page * data.queryForm.limit);
};

const handleRowClick = (row, column, event) => {
  if (area.value == 100) {
    multipleTableRef.value.toggleRowSelection(row);
  }
};

const handleRowClick_3 = (row, column, event) => {
  if (area.value == 100) {
    multipleTableRef_3.value.toggleRowSelection(row);
  }
};

const handleSelectionChange = (val) => {
  multipleSelection.value = val;
  let arr = multipleSelection.value.map((item) => {
    return item.deviceIndex;
  });
  num.value = arr[arr.length - 1];
  if (multipleSelection.value.length > 0) {
    district.value = multipleSelection.value[multipleSelection.value.length - 1].areaCode;
  }
};

const handleSelectionChange2 = (val) => {
  multipleSelection2.value = val;
};

const handleSelectionChange3 = (val) => {
  multipleSelection3.value = val;
};

const handleSelectionChange_3 = (val) => {
  multipleSelection_3.value = val;
};

const currentChange = (page) => {
  pageData.queryForm.page = page;
  getList(queryParams);
};

const sizeChange = (size) => {
  data.queryForm.page = size;
  getList(queryParams);
};

const add = () => {
  // 新增
};

const edit = (row) => {
  // 编辑
};
const onChanSize = (e) => {
  //修改分页数
  data.queryForm.page = 1;
  data.queryForm.limit = e;
  getList(queryParams);
};
const onChanPage = (e) => {
  //修改分页
  data.queryForm.page = e;
  getList(queryParams);
};

const del = (row) => {
  // 删除
  ElMessageBox.confirm("确认删除?", "提示").then(() => {
    let arr = JSON.parse(JSON.stringify([row]));
    for (let i = 0; i < arr.length; i++) {
      arr[i].action = 0;
    }
    let params = {
      deviceFid: pid.value,
      operationDevices: arr,
    };

    $axios.post("/operationDevice/updateBatch", params).then((res) => {
      if (res.data.code === 200) {
        layer.msg("删除成功！");
        layer.close(mainIndex);
        getList({ deviceFid: pid.value });
      } else {
        layer.msg("删除失败!");
        layer.close(mainIndex);
      }
    });
  });
};

let formRef = ref(null);

const submit = () => {
  // 提交新增/编辑表单
  formRef.value.validate((valid) => {
    if (valid) {
    }
  });
};

const getList = async (params, num) => {
  // 获取表格数据
  if (params.groupName == "全部") {
    delete params.groupName;
  }
  data.loading = true;
  let pom = {
    ...data.queryForm,
    ...params,
    deviceFid: pid.value,
    gatewayType: 1,
    limit: 10000,
    page: 1,
  };
  const res = await queryOperationDeviceAllList(pom);
  data.loading = false;
  if (res.data === "PARAMETER_LACK_ERROR") {
    return false;
  } else {
    for (let i = 0; i < res.data.records.length; i++) {
      if (res.data.records[i].areaCode) {
        res.data.records[i].areaCodeLabel = hex2int(res.data.records[i].areaCode.replace(/\s*/g, ""));
      }
      if (res.data.records[i].groupName) {
        res.data.records[i].groupNameLabel = hex2int(res.data.records[i].groupName.slice(1).replace(/\s*/g, ""));
      }
    }
    res.data.records = groupAndSort("groupNameLabel", "areaCodeLabel", res.data.records);
    res.data.records = res.data.records.sort(createComprisonFunction("areaCodeLabel"));
    recordsOld = JSON.parse(JSON.stringify(res.data.records));
    data.tableData = res.data.records.slice((data.queryForm.page - 1) * data.queryForm.limit, data.queryForm.page * data.queryForm.limit);
    wmStore.setDeviceNumberList(res.data.records.sort((a, b) => a.deviceIndex - b.deviceIndex));
    wmStore.setDeviceSetList(data.tableData);
    data.total = res.data.total;
  }
};

const showType = (type) => {
  if (type == -1) return "系统";
  if (type == 0) return "云平台";
  if (type == 1) return "云产品";
  if (type == 2) return "云设备";
};
let switchFlag = ref(false);
//全局列表
var tableIns;
//后台设定开灯值
var lightOnNum = 40;
//后台设定关灯值
var lightOffNum = 0;
//全局弹出
var mainIndex;
var $ = "";
var layer = "";
var form = "";
var table = "";
var dtree = "";
var slider = "";
var slider1 = "";
var slider2 = "";
var dropdown = "";
var maxNum = "";
var setTimeouts = "";
var tipsTime = "";
//渲染滑块
var lightNum = 0;
let total = 0;
let loading;

let params = {
  deviceFid: pid.value,
  mesh: {
    code: "",
    deviceName: pid.value,
    area: "",
    address: "00 00",
    action: "blink",
    params: "",
    identity: "",
  },
};

let dialogVisible = ref(false);
const moreOperate = () => {
  if (wsStore.gatewayId) {
    dialogVisible.value = true;
    sceneVisible.value = true;
    activeName.value = "first";
    getTab2();
  } else {
    ElNotification({ title: '系统提示:', message: `请先选择需要的网关`, type: 'warning', duration: 1500 })
  }
};

const getTab2 = async () => {
  let params = { deviceFid: pid.value, pageSize: 1000, pageNum: 1 };
  const data = await getAllDeviceTimingList(params);
  if (data.content) {
    data.content.forEach((element) => {
      element.operateInfoStr = element.operateInfo;
      element.operateInfoObj = JSON.parse(element.operateInfo);
      element.chooseWorkDayStr = element.chooseWorkDay;
      element.chooseWorkDayList = element.chooseWorkDay.split(",");
      element.operateInfo = JSON.parse(element.operateInfo);
    });
    wmStore.setTimedScenarioList(data);
  }
  sceneTableData.value = wmStore.timedScenarioObj.content;
};

const operate = (action) => {
  params.mesh.code = area.value;
  params.mesh.area = district.value;
  if (area.value == 400) {
    params.mesh.address = district.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }
  if (area.value == 100) {
    params.mesh.address = num.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
  }
  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }
  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }
  layer.msg("正在请求中......");
  data.loading2 = true;
  params.mesh.action = action;
  params.deviceFid = pid.value;
  params.mesh.deviceName = pid.value;
  params.mesh.params = action == "lightOn" ? lightOnNum : lightOffNum;

  $axios
    .post("/operation/mesh", params)
    .then((res) => {
      layer.msg("请求成功!");
      data.loading2 = false;
    })
    .catch((err) => {
      layer.msg("请求失败!");
    });
};

//加载框
const showLoad = (msg, tipsTime = 0) => {
  return layer.msg(msg, {
    icon: 16,
    shade: [0.5, "#f5f5f5"],
    time: tipsTime,
    scrollbar: false,
    offset: "auto",
  });
};
const operationalType = (operationalType, num, allFlag) => {
  let typeList = ["开灯", "调灯", "关灯", "多灯测试开", "多灯测试关", "调整色温"];
  layer.msg(`正在请求中....`);
  for (let i = 0; i < multipleSelection.value.length; i++) {
    let item = multipleSelection.value[i];
    let macs = (item.deviceIndex * 1).toString(16).toUpperCase().toString();
    if (macs.length == 2) {
      macs = "00" + macs;
    }
    let address = macs[0] + macs[1] + " " + macs[2] + macs[3];
    let params = {
      deviceFid: pid.value,
      mesh: {
        code: 100,
        deviceName: pid.value,
        area: item.areaCode,
        address: address,
        action: operationalType,
        params: "",
        identity: "",
      },
    };
    $axios
      .post("/operation/mesh", params)
      .then((res) => {
        data.loading = false;
        if (res.data.code === 200) {
          layer.msg(`${typeList[num]}请求发送成功`);
        } else {
          showLoad(`${typeList[num]}请求发送失败`, 1000);
        }
      })
      .catch((err) => { });
  }
};
const uniqueFunc = (arr, uniId) => {
  const res = new Map();
  return arr.filter((item) => !res.has(item[uniId]) && res.set(item[uniId], 1));
};

let options = ref([]);
let customName = ref("全部");
const arraySort = (key) => {
  return function (a, b) {
    if (a[key] < b[key]) return 1;
    if (b[key] > a[key]) return -1;
    return 0;
  };
};
const getDeviceAliasAllListFun = async () => {
  if (!pid.value) {
    return;
  }
  let formData = new FormData();
  formData.append("deviceFid", pid.value);
  const res = await getDeviceAliasAllList(formData);
  res.data.map((item) => {
    item.v = item.group_name;
    if (item.group_name.length > 3 && item.group_name.includes(" ")) {
      item.group_name = hex2int(item.group_name.replace(/\s*/g, "")) - 49152;
    }
  });
  options.value = uniqueFunc(res.data, "group_name");
  options.value.sort((a, b) => {
    return a.group_name - b.group_name;
  });
  wmStore.setDeviceGroupList(options.value);
  // options.value.unshift({ group_name: "全部", name: '全部', v: "全部" })
};

let deviceAreaAllList = ref([]);
const arrDistinctByProp = (arr, prop) => {
  let obj = {};
  return arr.reduce(function (preValue, item) {
    obj[item[prop]] ? "" : (obj[item[prop]] = true && preValue.push(item));
    return preValue;
  }, []);
};

const getDeviceAreaAllListFun = async () => {
  let formData = new FormData();
  formData.append("deviceFid", pid.value);
  const res = await getDeviceAreaAllList(formData);
  if (res.data !== null) {
    let newArr = arrDistinctByProp(res.data, "area_code");
    deviceAreaAllList.value = newArr;
    deviceAreaAllList.value = deviceAreaAllList.value.sort((a, b) => {
      return a.area_code - b.area_code;
    });
    wmStore.setDeviceAreaList(deviceAreaAllList.value);
  }
};

const setCustomName = () => {
  let params = {};
  if (customName.value == "全部") {
    params = { deviceFid: pid.value };
  } else {
    params = { groupName: customName.value, deviceFid: pid.value };
  }
  getList(params, 1);
  area.value = "200";
  let obj = options.value.filter((item) => {
    return item.v == customName.value;
  });
  group.value = obj[0].group_name;
};

const allLightOn = () => {
  layer.confirm("确定设备全部开灯？", function (index) {
    let params = {
      code: 400,
      deviceName: pid.value,
      area: "00 00",
      address: "00 00",
      action: "blink",
      params: "",
      identity: "",
    };

    $axios
      .post("/operation/mesh", params)
      .then((res) => {
        layer.msg("请求成功!");
        data.loading = false;
      })
      .catch((err) => {
        layer.msg("全设备开灯失败!");
      });
  });
};

const allLightAdjust = () => {
  params.mesh.code = area.value;
  params.mesh.area = district.value;
  if (area.value == 400) {
    params.mesh.address = district.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }

  if (area.value == 100) {
    params.mesh.address = num.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
  }

  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }

  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }

  /// layer.confirm('确定全设备调整亮度？', function (index1) {
  //   layer.close(index1);
  var _sensitivity = 0;
  slider.render({
    elem: "#slideTest1", //绑定元素
    input: true, //输入框
    min: 0,
    change: function (value) {
      _sensitivity = value;
    },
  });

  mainIndex = layer.open({
    type: 1,
    title: "调整全设备亮度:",
    content: $("#slideDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      layer.close(mainIndex);
      loading = showLoad("全设备调整亮度请求中...");

      $axios
        .post("/operation/mesh", {
          deviceFid: pid.value,
          mesh: {
            code: 400,
            deviceName: pid.value,
            area: "00 00",
            address: "00 00",
            action: "setHighBright",
            params: _sensitivity,
            identity: "",
          },
        })
        .then((res) => {
          layer.msg("请求成功!");
          data.loading = false;
        })
        .catch((err) => {
          layer.msg("请求失败!");
        });
    },
    success: function (index) { },
  });
};

const allAdjustColor = () => {
  params.mesh.code = area.value;
  params.mesh.area = district.value;
  if (area.value == 400) {
    params.mesh.address = district.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }

  if (area.value == 100) {
    params.mesh.address = num.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
  }

  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }

  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }

  layer.msg("调色请求中.....");
  var _sensitivity = 0;
  slider.render({
    elem: "#slideTest1", //绑定元素
    input: true, //输入框
    min: 0,
    change: function (value) {
      _sensitivity = value;
    },
  });

  mainIndex = layer.open({
    type: 1,
    title: "调整设备色温",
    content: $("#slideDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      layer.close(mainIndex);
      $axios
        .post("/operation/mesh", {
          deviceFid: pid.value,
          mesh: {
            code: 400,
            deviceName: pid.value,
            area: "00 00",
            address: "00 00",
            action: "setCctBright",
            params: _sensitivity,
            identity: "",
          },
        })
        .then((res) => {
          layer.msg("请求成功!");
          data.loading = false;
        })
        .catch((err) => {
          layer.msg("请求失败!");
        });

      //operationalType(5, _sensitivity, true)
    },
  });
};

const allTrigger = () => {
  mainIndex = layer.open({
    type: 1,
    title: "全感应头开关",
    content: $("#lightTestDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      params.mesh.code = area.value;
      params.mesh.area = district.value;
      if (area.value == 400) {
        params.mesh.address = district.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
      }

      if (area.value == 100) {
        params.mesh.address = num.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (num.value == "") {
          ElMessage.error("号不能为空");
          return;
        }
      }

      if (area.value == 200) {
        params.mesh.address = group.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (group.value === "") {
          ElMessage.error("组不能为空");
          return;
        }
      }

      if (area.value == 300) {
        params.mesh.address = tag.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (tag.value == "") {
          ElMessage.error("标签不能为空");
          return;
        }
      }

      layer.close(mainIndex);

      const lTestState = $('input[name="lTest"]:checked').val();
      loading = showLoad("全感应头开关请求中...");
      let params = {
        deviceFid: 134,
        mesh: {
          code: 400,
          deviceName: pid.value,
          area: "00 00",
          address: "00 00",
          action: "",
          params: "",
          identity: "",
        },
      };
      let action = "";
      if (lTestState == "0") {
        params.mesh.action = "setLightMode";
        params.mesh.params = "感应";
      } else {
        params.mesh.action = "setLightMode";
        params.mesh.params = "常亮";
      }
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          res = res.data;
          if (res.code === 200) {
            loading = showLoad("全感应头开关请求成功！", 500);
            let reqNum = 1;
            var timer = setInterval(function () {
              let code = JSON.parse(res.data).requestId;
            }, 2000);
          } else {
            layer.msg("感应头开关失败!");
          }
          data.loading = false;
        })
        .catch((err) => {
          layer.msg("请求失败!");
        });
    },
    success: function (index) { },
  });
};
let sliderValue13 = ref();
let sliderValue14 = ref();
let sliderValue17 = ref();
const changeArea = () => {
  multipleTableRef.value.clearSelection();
};

const operateStop = () => {
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: 400,
      deviceName: pid.value,
      area: "00 00",
      address: "00 00",
      action: "stopScan",
      params: "",
      identity: "",
    },
  };
  $axios
    .post("/operation/mesh", params)
    .then((res) => {
      data.loading = false;
      window.clearInterval(timer);
      if (res.data.code === 200) {
        // layer.msg(`调光请求发送成功`);
      } else {
        // showLoad(`调光请求发送失败`, 1000)
      }
    })
    .catch((err) => { });
  data.loading2 = false;
  window.clearInterval(timer);
};
const start = (item) => {
  let macs = (item.deviceIndex * 1).toString(16).toUpperCase().toString();
  if (macs.length == 2) {
    macs = "00" + macs;
  }
  let address = macs[0] + macs[1] + " " + macs[2] + macs[3];

  layer.msg("闪一闪请求成功!");
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: 100,
      deviceName: pid.value,
      area: item.areaCode,
      // "address": allFlag ? "FFFFFFFFFFFF" : macs.toString(),
      address: address,
      action: "blink",
      params: "",
      identity: "",
    },
  };
  $axios
    .post("/operation/mesh", params)
    .then((res) => {
      /// layer.msg("请求成功!");
      // data.loading = false;
      if (res.data.code === 200) {
        layer.msg(`闪一闪请求发送成功`);
      } else {
        showLoad(`闪一闪请求发送失败`, 1000);
      }
    })
    .catch((err) => { });
};

const operateScan = () => {
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: 400,
      deviceName: pid.value,
      area: "00 00",
      address: "00 00",
      action: "scan",
      params: "",
      identity: "",
    },
  };

  $axios
    .post("/operation/mesh", params)
    .then((res) => {
      data.loading = false;
    })
    .catch((err) => { });

  data.loading2 = true;
  window.clearInterval(timer);
  timer = window.setInterval(function () {
    if (dialogVisible2.value == false) {
      window.clearInterval(timer);
    }
    $axios
      .post("/operationDevice/scan", {
        deviceFid: pid.value,
      })
      .then((res) => {
        for (let i = 0; i < res.data.data.length; i++) {
          if (checkItem(res.data.data[i])) {
            data.tableData2.push(res.data.data[i]);
          }
        }
      });
  }, 1000);
};

const confirmAddLamp = () => {
  console.log('confirmAddLamp->transferScene',)
  let isOk = addLampRef.value.verificationRequ();
  const { addlampData } = addLampRef.value;
  console.log("addlampData->", addlampData);
  console.log('scenModel.data.operateInfoObj->', scenModel.data.operateInfoObj)
  if (isOk) {
    addlampData.forEach((element) => {
      element.params = transferScene.value
      scenModel.data.operateInfo.push(element);
    });
    scenModel.data.operateInfoObj = Array.from(new Set(scenModel.data.operateInfo));
    lampVisible.value = false;
  }
};

const deleteRepeat = (arr) => {
  arr = arr.map((item) => {
    return JSON.stringify(item);
  });
  return Array.from(new Set(arr)).map((item) => {
    return JSON.parse(item);
  });
};
const enterAdd = () => {
  window.clearInterval(timer);
  //console.log(multipleSelection2.value);
  let arr = JSON.parse(JSON.stringify(multipleSelection2.value));
  for (let i = 0; i < arr.length; i++) {
    arr[i].action = 1;
    if (arr[i].hasOwnProperty("flag")) {
      delete arr[i].flag;
    }
  }

  let params = {
    deviceFid: pid.value,
    operationDevices: arr,
  };

  $axios.post("/operationDevice/updateBatch", params).then((res) => {
    if (res.data.code == 200 && res.data.data) {
      layer.msg("新增成功！");
      dialogVisible2.value = false;
      window.clearInterval(timeLamp);
      getList({ deviceFid: pid.value });
    } else {
      layer.msg("新增失败！");
    }
  });
};
const close = () => {
  dialogVisible2.value = false;
  window.clearInterval(timer);
  window.clearInterval(timeLamp);
};
const allDarkenDelay = () => {
  slider.render({
    elem: "#slideTest1", //绑定元素
    input: true, //输入框
    min: 0,
    change: function (value) {
      lightNum = value;
    },
  });
  mainIndex = layer.open({
    type: 1,
    title: "全部关灯延时",
    content: $("#slideDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      let params = {
        deviceFid: pid.value,
        mesh: {
          code: 400,
          deviceName: pid.value,
          area: "00 00",
          address: "00 00",
          action: "setDelayTime",
          params: lightNum,
          identity: "",
        },
      };
      params.mesh.code = area.value;
      params.mesh.area = district.value;
      if (area.value == 400) {
        params.mesh.address = district.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
      }
      if (area.value == 100) {
        params.mesh.address = num.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (num.value == "") {
          ElMessage.error("号不能为空");
          return;
        }
      }
      if (area.value == 200) {
        params.mesh.address = group.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (group.value === "") {
          ElMessage.error("组不能为空");
          return;
        }
      }
      if (area.value == 300) {
        params.mesh.address = tag.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (tag.value == "") {
          ElMessage.error("标签不能为空");
          return;
        }
      }
      layer.close(mainIndex);
      loading = showLoad("全部关灯延时请求中...");
      $axios.post("/operation/mesh", params).then((res) => {
        if (res.data.code === 200) {
          layer.msg("全部关灯延时请求成功！");
        } else {
          layer.msg("全部关灯延时调整失败!");
        }
      });
      let params2 = {
        deviceFid: pid.value,
        mesh: {
          code: 400,
          deviceName: pid.value,
          area: "00 00",
          address: "00 00",
          action: "setDelayMode",
          params: "一段",
          identity: "",
        },
      };
      $axios.post("/operation/mesh", params2).then((res) => {
        if (res.data.code === 200) {
          layer.msg("全部关灯延时请求成功！");
        } else {
          layer.msg("全部关灯延时调整失败!");
        }
      });
    },
    success: function (index) { },
  });
};
const allLightTest = () => {
  mainIndex = layer.open({
    type: 1,
    title: "全灯测试",
    content: $("#lightTestDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      layer.close(mainIndex);
      const lTestState = $('input[name="lTest"]:checked').val();

      let params = {
        deviceFid: pid.value,
        mesh: {
          code: 400,
          deviceName: pid.value,
          area: "00 00",
          address: "00 00",
          action: "blink",
          params: "",
          identity: "",
        },
      };
      params.mesh.code = area.value;
      params.mesh.area = district.value;
      if (area.value == 400) {
        params.mesh.address = district.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
      }

      if (area.value == 100) {
        params.mesh.address = num.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (num.value == "") {
          ElMessage.error("号不能为空");
          return;
        }
      }

      if (area.value == 200) {
        params.mesh.address = group.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (group.value === "") {
          ElMessage.error("组不能为空");
          return;
        }
      }

      if (area.value == 300) {
        params.mesh.address = tag.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (tag.value == "") {
          ElMessage.error("标签不能为空");
          return;
        }
      }

      loading = showLoad("全灯测试请求中...");
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          if (res.data.code === 200) {
            layer.msg("全灯测试请求成功！");
            let reqNum = 1;
          } else {
            layer.msg("全灯测试失败!");
          }
          data.loading = false;
        })
        .catch((err) => {
          layer.msg("全灯测试失败!");
        });
    },
    success: function (index) { },
  });
};
const gradually = () => {
  let _sensitivity = 0;
  slider.render({
    elem: "#slide3", //绑定元素
    input: true, //输入框
    min: 0,
    max: 9,
    change: function (value) {
      _sensitivity = value;
    },
  });

  let _sensitivity2 = 0;
  slider.render({
    elem: "#slide4", //绑定元素
    input: true, //输入框
    min: 0,
    max: 9,
    change: function (value) {
      _sensitivity2 = value;
    },
  });

  mainIndex = layer.open({
    type: 1,
    title: "全渐亮灭",
    content: $("#slideDiv3"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      params.mesh.code = area.value;
      params.mesh.area = district.value;
      if (area.value == 400) {
        params.mesh.address = district.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
      }

      if (area.value == 100) {
        params.mesh.address = num.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (num.value == "") {
          ElMessage.error("号不能为空");
          return;
        }
      }

      if (area.value == 200) {
        params.mesh.address = group.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (group.value === "") {
          ElMessage.error("组不能为空");
          return;
        }
      }

      if (area.value == 300) {
        params.mesh.address = tag.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (tag.value == "") {
          ElMessage.error("标签不能为空");
          return;
        }
      }

      layer.close(mainIndex);
      let sendMsg = "FFFFFFFFFFFF";
      let len = 1;
      let msg = "";
      if (11 < _sensitivity || _sensitivity < 0) {
        return layer.msg("只接受0~11档位");
      }
      msg = _sensitivity.toString(16).toUpperCase().padStart(2, "0") + len.toString(16).toUpperCase().padStart(2, "0") + sendMsg;
      //console.log(msg)
      /// sensitivity(0, msg, _sensitivity)

      let params = {
        deviceFid: pid.value,
        mesh: {
          code: 400,
          deviceName: pid.value,
          area: "00 00",
          address: "00 00",
          action: "setBrightRiseTime",
          params: _sensitivity,
          identity: "",
        },
      };

      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          /// layer.msg("请求成功!");
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(`全渐亮灭请求发送成功`);
          } else {
            showLoad(`全渐亮灭发送失败`, 1000);
          }
        })
        .catch((err) => { });

      let params2 = {
        deviceFid: pid.value,
        mesh: {
          code: 400,
          deviceName: pid.value,
          area: "00 00",
          address: "00 00",
          action: "setBrightFallTime",
          params: _sensitivity2,
          identity: "",
        },
      };

      $axios
        .post("/operation/mesh", params2)
        .then((res) => {
          /// layer.msg("请求成功!");
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(`全渐亮灭请求发送成功`);
          } else {
            showLoad(`全渐亮灭发送失败`, 1000);
          }
        })
        .catch((err) => { });
    },
  });
};
const allSensitivity = () => {
  let _sensitivity = 0;
  slider.render({
    elem: "#slideTest1", //绑定元素
    input: true, //输入框
    min: 0,
    max: 11,
    change: function (value) {
      _sensitivity = value;
    },
  });
  mainIndex = layer.open({
    type: 1,
    title: "调整感应头灵敏度",
    content: $("#slideDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      params.mesh.code = area.value;
      params.mesh.area = district.value;
      if (area.value == 400) {
        params.mesh.address = district.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
      }

      if (area.value == 100) {
        params.mesh.address = num.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (num.value == "") {
          ElMessage.error("号不能为空");
          return;
        }
      }

      if (area.value == 200) {
        params.mesh.address = group.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (group.value === "") {
          ElMessage.error("组不能为空");
          return;
        }
      }

      if (area.value == 300) {
        params.mesh.address = tag.value;
        if (district.value === "") {
          ElMessage.error("区不能为空");
          return;
        }
        if (tag.value == "") {
          ElMessage.error("标签不能为空");
          return;
        }
      }

      layer.close(mainIndex);
      let sendMsg = "FFFFFFFFFFFF";
      let len = 1;
      let msg = "";
      if (11 < _sensitivity || _sensitivity < 0) {
        return layer.msg("只接受0~11档位");
      }
      msg = _sensitivity.toString(16).toUpperCase().padStart(2, "0") + len.toString(16).toUpperCase().padStart(2, "0") + sendMsg;
      //console.log(msg)
      sensitivity(0, msg, _sensitivity);
    },
  });
};
const unique = (arr, val) => {
  const res = new Map();
  return arr.filter((item) => !res.has(item[val]) && res.set(item[val], 1));
};
let dialogTableVisible = ref(false);
let gridData = ref([]);
const setAlert = () => {
  dialogTableVisible.value = true;
  getArr();
};
const getArr = () => {
  $.get($httpUrl + "/operationDevice/getBlinkDev?fid=" + 50, {}, function (res) {
    gridData.value = res.data;
  });
};

const itemPropertie = () => {
  if (multipleSelection.value.length == 0) {
    layer.msg("请至少选中一个设备");
    return;
  }
  var mainIndex = layer.confirm("确定选中获取设备属性？", function (index) {
    // let params2 = {
    //   "deviceFid": pid.value,
    //   "mesh":
    //   {
    //     "code": 400,
    //     "deviceName": pid.value,
    //     "area": '00 00',
    //     "address": '00 00',
    //     "action": 'reportSettingAck',
    //     "params": '',
    //     "identity": ""
    //   }
    // }

    // for(let i=0;i<  multipleSelection.value.length;i++){
    //   let params=  multipleSelection.value[i];

    let params2 = {
      deviceFid: pid.value,
      mesh: {
        code: area.value,
        deviceName: pid.value,
        area: "00 00",
        address: "00 00",
        action: "reportSettingAck",
        params: "",
        identity: "",
      },
      operationDevices: multipleSelection.value,
    };
    let loading = showLoad("单设备属性请求中...");

    $axios
      .post("/operation/meshGet1Attribute", params2)
      .then((res) => {
        if (res.data.code === 200) {
          layer.msg(`操作成功`);
          layer.close(mainIndex);
        } else {
          showLoad(`操作失败`, 1000);
          layer.close(mainIndex);
        }
      })
      .catch((err) => { });
    //}
  });
};

let ts = 0;
const allPropertie = () => {
  if (Math.round(new Date()) - ts > 1000 * 10) {
  } else {
    // layer.msg(`请隔10s再点击`);
    // return false;
  }
  var mainIndex = layer.confirm("确定批量获取设备属性？", function (index) {
    let params2 = {
      deviceFid: pid.value,
      mesh: {
        code: 400,
        deviceName: pid.value,
        area: "00 00",
        address: "00 00",
        action: "reportSettingAck",
        params: "",
        identity: "",
      },
    };

    $axios
      .post("/operation/meshGetAttribute", params2)
      .then((res) => {
        ts = Math.round(new Date());
        /// layer.msg("请求成功!");
        /// data.loading = false;
        if (res.data.code === 200) {
          layer.msg(`批量获取设备属性请求发送成功，稍后刷新看到结果！`);
          layer.close(mainIndex);
        } else {
          showLoad(`操作失败`, 1000);
          layer.close(mainIndex);
        }
      })
      .catch((err) => { });
  });
  return;
};

const closeDialog = () => {
  window.clearInterval(timer);
  window.clearInterval(timer2);
  window.clearInterval(timeLamp);
  iconFlag.value = false;
  dialogVisible2.value = false;
  data.loading2 = false;
  searchFlag.value = false;
  searchHtml.value = "网关搜灯";
};

let dialogVisible2 = ref(false);
let timer = null;
const newAdd = () => {
  timeLamp = window.setInterval(function () {
    getDeviceAliasAllListFun();
  }, 1000);
  data.tableData2 = [];
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: 400,
      deviceName: pid.value,
      area: "00 00",
      address: "00 00",
      action: "scan",
      params: "",
      identity: "",
    },
  };

  $axios
    .post("/operation/mesh", params)
    .then((res) => {
      data.loading = false;
      if (res.data.code === 200) {
        // layer.msg(`调光请求发送成功`);
      } else {
        // showLoad(`调光请求发送失败`, 1000)
      }
    })
    .catch((err) => { });
  data.loading2 = true;
  dialogVisible2.value = true;
  timer = window.setInterval(function () {
    if (dialogVisible2.value == false) {
      window.clearInterval(timer);
    }
    $axios
      .post("/operationDevice/scan", {
        deviceFid: pid.value,
      })
      .then((res) => {
        for (let i = 0; i < res.data.data.length; i++) {
          if (checkItem(res.data.data[i])) {
            data.tableData2.push(res.data.data[i]);
          }
        }
      });
  }, 1000);
};

const checkItem = (order) => {
  let arr = data.tableData2.filter((item) => {
    return item.id == order.id;
  });
  if (arr.length > 0) {
    return false;
  } else {
    return true;
  }
};
const lightOn = () => {
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }
  operationalType("lightOn", 0, false);
};

const adjustLight = () => {
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }
  var _sensitivity = 0;
  slider.render({
    elem: "#slideTest1", //绑定元素
    input: true, //输入框
    min: 0,
    change: function (value) {
      _sensitivity = value;
    },
  });
  mainIndex = layer.open({
    type: 1,
    title: "调整设备亮度",
    content: $("#slideDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      layer.close(mainIndex);

      for (let i = 0; i < multipleSelection.value.length; i++) {
        let item = multipleSelection.value[i];
        let macs = (item.deviceIndex * 1).toString(16).toUpperCase().toString();
        if (macs.length == 2) {
          macs = "00" + macs;
        }
        let address = macs[0] + macs[1] + " " + macs[2] + macs[3];

        let params = {
          deviceFid: pid.value,
          mesh: {
            code: 100,
            deviceName: pid.value,
            area: item.areaCode,
            // "address": allFlag ? "FFFFFFFFFFFF" : macs.toString(),
            address: address,
            action: "setHighBright",
            params: _sensitivity,
            identity: "",
          },
        };

        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            /// layer.msg("请求成功!");
            data.loading = false;
            if (res.data.code === 200) {
              // showLoad(`${typeList[operationalType]}请求发送成功`, 1000)
              layer.msg(`调光请求发送成功`);
            } else {
              showLoad(`调光请求发送失败`, 1000);
            }
          })
          .catch((err) => { });
      }
    },
  });
};
const adjustColor = () => {
  var _sensitivity = 0;
  slider.render({
    elem: "#slideTest1", //绑定元素
    input: true, //输入框
    min: 0,
    change: function (value) {
      _sensitivity = value;
    },
  });
  mainIndex = layer.open({
    type: 1,
    title: "调整设备色温",
    content: $("#slideDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      layer.close(mainIndex);

      for (let i = 0; i < multipleSelection.value.length; i++) {
        let item = multipleSelection.value[i];
        let macs = (item.deviceIndex * 1).toString(16).toUpperCase().toString();
        if (macs.length == 2) {
          macs = "00" + macs;
        }
        let address = macs[0] + macs[1] + " " + macs[2] + macs[3];

        let params = {
          deviceFid: pid.value,
          mesh: {
            code: 100,
            deviceName: pid.value,
            area: item.areaCode,
            // "address": allFlag ? "FFFFFFFFFFFF" : macs.toString(),
            address: address,
            action: "setCctBright",
            params: _sensitivity,
            identity: "",
          },
        };

        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            /// layer.msg("请求成功!");
            data.loading = false;
            if (res.data.code === 200) {
              // showLoad(`${typeList[operationalType]}请求发送成功`, 1000)

              layer.msg(`调色请求发送成功`);
            } else {
              showLoad(`调色请求发送失败`, 1000);
            }
          })
          .catch((err) => { });
      }
    },
  });
};

const setLightNum = () => {
  let lightNum1 = 0;
  let lightNum2 = 0;
  let ins1 = slider1.render({
    elem: "#slide1", //绑定元素
    input: true, //输入框
    min: 0,
    max: 100,
    value: lightOffNum,
    change: function (value) {
      lightNum1 = value;
    },
  });
  let ins2 = slider2.render({
    elem: "#slide2", //绑定元素
    input: true, //输入框
    min: 10,
    max: 100,
    value: lightOnNum,
    change: function (value) {
      lightNum2 = value;
    },
  });
  if (lightOnNum !== 0) {
    lightNum1 = lightOffNum;
    lightNum2 = lightOnNum;
  } else {
    lightNum1 = 0;
    lightNum2 = 20;
  }
  mainIndex = layer.open({
    type: 1,
    title: "设置开关灯值:",
    content: $("#slideDiv2"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      $.post(
        $httpUrl + "/userLightNum/setUserLightNum",
        {
          deviceFid: pid.value,
          lightOnNum: lightNum2,
          lightOffNum: lightNum1,
        },
        function (res) {
          if (res.code === 200) {
            layer.msg("设置成功！");
            layer.close(mainIndex);
            lightOffNum = lightNum1;
            lightOnNum = lightNum2;

            let params = {
              deviceFid: pid.value,
              mesh: {
                code: 400,
                deviceName: pid.value,
                area: "00 00",
                address: "00 00",
                action: "setHighBright",
                params: lightNum2,
                identity: "",
              },
            };

            $axios
              .post("/operation/mesh", params)
              .then((res) => {
                /// layer.msg("请求成功!");
                data.loading = false;
                if (res.data.code === 200) {
                } else {
                  /// showLoad(`调色请求发送失败`, 1000)
                }
              })
              .catch((err) => { });

            let params2 = {
              deviceFid: pid.value,
              mesh: {
                code: 400,
                deviceName: pid.value,
                area: "00 00",
                address: "00 00",
                action: "setStandbyBright",
                params: lightNum1,
                identity: "",
              },
            };

            $axios
              .post("/operation/mesh", params2)
              .then((res) => {
                /// layer.msg("请求成功!");
                data.loading = false;
                if (res.data.code === 200) {
                } else {
                  /// showLoad(`调色请求发送失败`, 1000)
                }
              })
              .catch((err) => { });
          } else {
            layer.msg("设置失败！");
          }
        }
      );
    },
  });
};

const setsensitivity = () => {
  var _sensitivity = 0;
  let sendMsg1 = "";
  let len = 0;
  let msg = "";
  for (let i in multipleSelection.value) {
    sendMsg1 += multipleSelection.value[i].macaddress;
    len += 1;
  }
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }
  slider.render({
    elem: "#slideTest1", //绑定元素
    input: true, //输入框
    min: 0,
    max: 11,
    change: function (value) {
      _sensitivity = value;
    },
  });
  mainIndex = layer.open({
    type: 1,
    title: "调整感应头灵敏度",
    content: $("#slideDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      layer.close(mainIndex);

      if (11 < _sensitivity || _sensitivity < 0) {
        return layer.msg("只接受0~11档位");
      }
      msg = _sensitivity.toString(16).toUpperCase().padStart(2, "0") + len.toString(16).toUpperCase().padStart(2, "0") + sendMsg1;
      //console.log(msg)
      sensitivity(1, msg);
    },
  });
};
const lightTest = () => {
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }

  layer.msg("正在请求中....");
  mainIndex = layer.open({
    type: 1,
    title: "单灯测试",
    content: $("#lightTestDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      layer.close(mainIndex);
      let lTestState = $('input[name="lTest"]:checked').val();
      if (lTestState === "0") {
        /// operationalType(3)
        /// //console.log(lTestState)
        for (let i = 0; i < multipleSelection.value.length; i++) {
          let item = multipleSelection.value[i];
          let macs = (item.deviceIndex * 1).toString(16).toUpperCase().toString();
          if (macs.length == 2) {
            macs = "00" + macs;
          }
          let address = macs[0] + macs[1] + " " + macs[2] + macs[3];

          let params = {
            deviceFid: pid.value,
            mesh: {
              code: 100,
              deviceName: pid.value,
              area: item.areaCode,
              // "address": allFlag ? "FFFFFFFFFFFF" : macs.toString(),
              address: address,
              action: "blink",
              params: "",
              identity: "",
            },
          };

          $axios
            .post("/operation/mesh", params)
            .then((res) => {
              /// layer.msg("请求成功!");
              data.loading = false;
              if (res.data.code === 200) {
                // showLoad(`${typeList[operationalType]}请求发送成功`, 1000)

                layer.msg(`单灯测试请求发送成功`);
              } else {
                showLoad(`单灯测试请求发送失败`, 1000);
              }
            })
            .catch((err) => { });
        }
      } else {
        //// operationalType(4)
        ///   //console.log(lTestState)
        for (let i = 0; i < multipleSelection.value.length; i++) {
          let item = multipleSelection.value[i];
          let macs = (item.deviceIndex * 1).toString(16).toUpperCase().toString();
          if (macs.length == 2) {
            macs = "00" + macs;
          }
          let address = macs[0] + macs[1] + " " + macs[2] + macs[3];

          let params = {
            deviceFid: pid.value,
            mesh: {
              code: 100,
              deviceName: pid.value,
              area: item.areaCode,
              // "address": allFlag ? "FFFFFFFFFFFF" : macs.toString(),
              address: address,
              action: "stopBlink",
              params: "",
              identity: "",
            },
          };

          $axios
            .post("/operation/mesh", params)
            .then((res) => {
              /// layer.msg("请求成功!");
              data.loading = false;
              if (res.data.code === 200) {
                // showLoad(`${typeList[operationalType]}请求发送成功`, 1000)

                layer.msg(`单灯测试请求发送成功`);
              } else {
                showLoad(`单灯测试请求发送失败`, 1000);
              }
            })
            .catch((err) => { });
        }
      }
    },
  });
};

const sensitivity = (operationalType, msg, _sensitivity) => {
  let typeList = ["感应头灵敏度", "设置灵敏度"];
  loading = showLoad(`${typeList[operationalType]}请求中...`);
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: 400,
      deviceName: pid.value,
      area: "00 00",
      address: "00 00",
      action: "setSensorIntrval",
      params: _sensitivity,
      identity: "",
    },
  };
  $axios.post("/operation/mesh", params).then((res) => {
    if (res.data.code === 200) {
      layer.msg("灵敏度设置请求成功！");
    } else {
      layer.msg("灵敏度设置请求失败!");
    }
  });
};

const lightOff = () => {
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }
  operationalType("lightOff", 2, false);
};

const setArea = () => {
  $("#areaCode").val("");
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }
  //layer.msg(`正在设置中....`);
  mainIndex = layer.open({
    type: 1,
    title: "设置区号",
    content: $("#lightNameDiv4"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      const areaCode = $("#areaCode").val();
      if (areaCode == "") {
        layer.msg("区号不能为空");
        return false;
      }

      let load = layer.msg("正在设置中...", {
        icon: 16,
        shade: [0.5, "#f5f5f5"],
        time: 0,
        scrollbar: false,
        offset: "auto",
      });

      let arr = JSON.parse(JSON.stringify(multipleSelection.value));
      for (let i = 0; i < arr.length; i++) {
        //arr[i].areaCode = areaCode;
      }

      let param = {};

      param = {
        deviceFid: pid.value,
        mesh: {
          code: "100",
          deviceName: pid.value,
          area: "00 08",
          address: "00 08",
          action: "setAreaAddress",
          params: $("#areaCode").val(),
          identity: "",
        },
      };

      for (let i = 0; i < arr.length; i++) {
        param.mesh.area = arr[i].areaCode;
        param.mesh.address = arr[i].deviceIndex;
        $axios.post("/operation/mesh", param).then((res) => {
          if (res.data.code === 200) {
            layer.msg("设置成功！");
            layer.close(mainIndex);
          } else {
            layer.msg("设置失败!");
            layer.close(mainIndex);
          }
        });
      }
    },
  });
};
const groupNum = () => {
  $("#groupNum").val("");
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }

  mainIndex = layer.open({
    type: 1,
    title: "设置组号",
    content: $("#lightNameDiv2"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      const groupNum = $("#groupNum").val();
      if (groupNum == "") {
        layer.msg("组号不能为空");
        return false;
      }
      let sendMsg = "";
      let len = 0;
      let msg = "";
      for (let i in multipleSelection.value) {
        //  ls.push(rowsData[i].data.id)
        sendMsg += multipleSelection.value[i].macaddress;
        len += 1;
      }

      let load = layer.msg("正在设置中...", {
        icon: 16,
        shade: [0.5, "#f5f5f5"],
        time: 0,
        scrollbar: false,
        offset: "auto",
      });

      let arr = JSON.parse(JSON.stringify(multipleSelection.value));
      for (let i = 0; i < arr.length; i++) {
        // arr[i].groupName = groupNum;
      }

      let param = {
        deviceFid: pid.value,
        mesh: {
          code: 200,
          deviceName: pid.value,
          area: "00 00",
          address: "00 00",
          action: "setClusterAddress",
          params: groupNum,
          identity: "",
        },
      };

      for (let i = 0; i < arr.length; i++) {
        param.mesh.area = arr[i].areaCode;
        param.mesh.address = arr[i].groupName;

        $axios.post("/operation/mesh", param).then((res) => {
          if (arr.length - 1 == i) {
            window.setTimeout(function () {
              doQuery(queryParams);
            }, 1000);
          }
          if (res.data.code === 200) {
            layer.msg("设置成功！");
          } else {
            layer.msg("设置失败!");
          }
          layer.close(mainIndex);
        });
      }
    },
  });
};

const setArea3 = () => {
  $("#areaCode_3").val("");
  let ls = multipleSelection_3.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }
  //layer.msg(`正在设置中....`);
  mainIndex = layer.open({
    type: 1,
    title: "设置区号",
    content: $("#lightNameDiv4_3"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      const areaCode = $("#areaCode_3").val();
      if (areaCode == "") {
        layer.msg("区号不能为空");
        return false;
      }

      let load = layer.msg("正在设置中...", {
        icon: 16,
        shade: [0.5, "#f5f5f5"],
        time: 0,
        scrollbar: false,
        offset: "auto",
      });

      let arr = JSON.parse(JSON.stringify(multipleSelection_3.value));
      for (let i = 0; i < arr.length; i++) {
        //arr[i].areaCode = areaCode;
      }
      // let params = {
      //   "deviceFid": pid.value,
      //   "operationDevices":
      //     arr
      // }

      let param = {
        // "deviceFid": pid.value,
        // "mesh": {
        //   "code": 400,
        //   "deviceName": pid.value,
        //   "area": "00 00",
        //   "address": "00 00",
        //   "action": "setAreaAddress",
        //   "params": areaCode,
        //   "identity": ""
        // }
      };

      param = {
        deviceFid: pid.value,
        mesh: {
          code: "100",
          deviceName: pid.value,
          area: "00 08",
          address: "00 08",
          action: "setAreaAddress",
          params: $("#areaCode_3").val(),
          identity: "",
        },
      };

      for (let i = 0; i < arr.length; i++) {
        param.mesh.area = arr[i].areaCode;
        param.mesh.address = arr[i].deviceIndex;
        $axios.post("/operation/mesh", param).then((res) => {
          getArr();
          if (res.data.code === 200) {
            layer.msg("设置成功！");
            layer.close(mainIndex);
          } else {
            layer.msg("设置失败!");
            layer.close(mainIndex);
          }
        });
      }
    },
  });
};
const groupNum3 = () => {
  $("#groupNum_3").val("");
  let ls = multipleSelection_3.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }

  mainIndex = layer.open({
    type: 1,
    title: "设置组号",
    content: $("#lightNameDiv2_3"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      const groupNum = $("#groupNum_3").val();
      if (groupNum == "") {
        layer.msg("组号不能为空");
        return false;
      }
      let sendMsg = "";
      let len = 0;
      let msg = "";
      for (let i in multipleSelection_3.value) {
        sendMsg += multipleSelection_3.value[i].macaddress;
        len += 1;
      }
      let load = layer.msg("正在设置中...", {
        icon: 16,
        shade: [0.5, "#f5f5f5"],
        time: 0,
        scrollbar: false,
        offset: "auto",
      });
      let arr = JSON.parse(JSON.stringify(multipleSelection_3.value));
      let param = {
        deviceFid: pid.value,
        mesh: {
          code: 200,
          deviceName: pid.value,
          area: "00 00",
          address: "00 00",
          action: "setClusterAddress",
          params: groupNum,
          identity: "",
        },
      };

      for (let i = 0; i < arr.length; i++) {
        param.mesh.area = arr[i].areaCode;
        param.mesh.address = arr[i].groupName;
        $axios.post("/operation/mesh", param).then((res) => {
          if (arr.length - 1 == i) {
            window.setTimeout(function () {
              doQuery(queryParams);
            }, 1000);
          }
          getArr();
          if (res.data.code === 200) {
            layer.msg("设置成功！");
          } else {
            layer.msg("设置失败!");
          }
          layer.close(mainIndex);
        });
      }
    },
  });
};

const ungroup3 = () => {
  let ls = multipleSelection_3.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }
  const groupNum = "00";
  let sendMsg = "";
  let len = 0;
  let msg = "";
  for (let i in multipleSelection_3.value) {
    // ls.push(rowsData[i].data.id)
    sendMsg += multipleSelection_3.value[i].macaddress;
    len += 1;
  }

  if (groupNum) {
    if (!/^[0-9a-fA-F]{1,2}$/.test(groupNum)) {
      return layer.msg("组号不合法,应为2位16进制");
    }
    msg = groupNum.toUpperCase().padStart(2, "0") + "00" + len.toString(16).toUpperCase().padStart(2, "0") + sendMsg;
  }
  let load = layer.msg("正在解除中...", {
    icon: 16,
    shade: [0.5, "#f5f5f5"],
    time: 0,
    scrollbar: false,
    offset: "auto",
  });
  $.post(
    $httpUrl + "/operation/setGroup",
    {
      msg: msg,
      fid: pid.value,
    },
    function (res) {
      if (res.data == "fail" || res.data == null || !res.data) {
        layer.msg("设置失败");
        layer.close(mainIndex);
      } else {
        layer.close(mainIndex);
        layer.msg("设置成功！");
        for (let i in rowsData) {
          if (rowsData[i].checked) {
            rowsData[i].update({
              groupName: groupNum.toUpperCase().padStart(2, "0"),
            });
          }
        }
      }
      $("#groupNum_3").val("");
    }
  );
};

const ungroup = () => {
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }
  const groupNum = "00";
  let sendMsg = "";
  let len = 0;
  let msg = "";
  for (let i in multipleSelection.value) {
    // ls.push(rowsData[i].data.id)
    sendMsg += multipleSelection.value[i].macaddress;
    len += 1;
  }

  if (groupNum) {
    if (!/^[0-9a-fA-F]{1,2}$/.test(groupNum)) {
      return layer.msg("组号不合法,应为2位16进制");
    }
    msg = groupNum.toUpperCase().padStart(2, "0") + "00" + len.toString(16).toUpperCase().padStart(2, "0") + sendMsg;
  }
  //console.log(msg)

  let load = layer.msg("正在解除中...", {
    icon: 16,
    shade: [0.5, "#f5f5f5"],
    time: 0,
    scrollbar: false,
    offset: "auto",
  });

  // let params = {
  //   "deviceFid": pid.value,
  //   "mesh": {
  //     "code": 400,
  //     "deviceName": pid.value,
  //     "area": "00 00",
  //     "address": "00 00",
  //     "action": "relieve",
  //     "params": '',
  //     "identity": ""
  //   }
  // };
  // $axios.post('/operation/mesh',
  //   params).then(res => {
  //     if (res.data.code === 200) {
  //       layer.msg("解除成功！");
  //     } else {
  //       layer.msg("解除失败!");
  //     }
  //   })

  let arr = JSON.parse(JSON.stringify(multipleSelection.value));
  for (let i = 0; i < arr.length; i++) {
    arr[i].groupName = "00";
  }
  let params = {
    deviceFid: pid.value,
    operationDevices: arr,
  };

  $axios.post("/operationDevice/updateBatch", params).then((res) => {
    if (res.data.code === 200) {
      layer.msg("解除成功！");
      layer.close(mainIndex);
      getList({ deviceFid: pid.value });
    } else {
      layer.msg("解除失败!");
      layer.close(mainIndex);
    }
  });
};

const unbind = () => {
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }
  let arr = JSON.parse(JSON.stringify(multipleSelection.value));
  for (let i = 0; i < arr.length; i++) {
    arr[i].action = 0;
  }
  let params = {
    deviceFid: pid.value,
    operationDevices: arr,
  };

  ElMessageBox.confirm("确定要删除吗?", "提示").then(() => {
    $axios.post("/operationDevice/deleteBatch", params).then((res) => {
      if (res.data.code === 200) {
        layer.msg("删除成功！");
        layer.close(mainIndex);
        getList({ deviceFid: pid.value });
      } else {
        layer.msg("删除失败!");
        layer.close(mainIndex);
      }
    });
  });
};
const updateCustomName = () => {
  $("#customName").val("");
  let ls = multipleSelection.value.map((item) => {
    return item.id;
  });
  if (ls.length == 0) {
    layer.msg("还未选择设备！");
    return;
  }

  mainIndex = layer.open({
    type: 1,
    title: "当前设备:",
    content: $("#lightNameDiv"),
    area: ["40%", "35%"],
    btnAlign: "c",
    btn: ['<div class="layui-icon layui-icon-release">确定</div>', '<div class="layui-icon layui-icon-close">取消</div>'],
    yes: function (index, layero) {
      const customName1 = $("#customName").val();
      let arr = JSON.parse(JSON.stringify(multipleSelection.value));
      for (let i = 0; i < arr.length; i++) {
        arr[i].customName = customName1;
      }
      let params = {
        deviceFid: pid.value,
        operationDevices: arr,
      };
      layer.msg(`正在设置中....`);
      $axios.post("/operationDevice/updateBatch", params).then((res) => {
        if (res.data.code === 200) {
          layer.msg("设置成功！");
          layer.close(mainIndex);
          getList({ deviceFid: pid.value, groupName: customName.value });
          getDeviceAliasAllListFun();
        } else {
          layer.msg("设置失败!");
          layer.close(mainIndex);
        }
      });
    },
  });
};
let area = ref("");
let gateway = ref("");

let darrOptions = ref([
  {
    label: i18n.language === "zh-cn" ? "场所灯操作" : "Placelightoperation",
    value: "",
  },
  {
    label: i18n.language === "zh-cn" ? "区操作" : "Zoneoperation",
    value: "400",
  },
  {
    label: i18n.language === "zh-cn" ? "单灯操作" : "Singlelampoperation",
    value: "100",
  },
  {
    label: i18n.language === "zh-cn" ? "群组操作" : "Groupoperation",
    value: "200",
  },
  {
    label: i18n.language === "zh-cn" ? "标签操作" : "Labeloperation",
    value: "300",
  },
]);
let value17 = ref();
let radio1 = ref("常亮");
let sliderValue = ref(0);
let sliderValue2 = ref(0);
let sliderValue3 = ref(0);
let sliderValue4 = ref(1);
let radio2 = ref("一段");
let radio3 = ref("无效");
let dateOptions = ref([
  {
    value: "0",
    label: "0秒",
  },
  {
    value: "5",
    label: "5秒",
  },
  {
    value: "10",
    label: "10秒",
  },
  {
    value: "20",
    label: "20秒",
  },
  {
    value: "60",
    label: "60秒",
  },
  {
    value: "120",
    label: "120秒",
  },
  {
    value: "300",
    label: "300秒",
  },
  {
    value: "600",
    label: "600秒",
  },
  {
    value: "900",
    label: "900秒",
  },
  {
    value: "1800",
    label: "1800秒",
  },
]);
let switchValue = ref(false);
let switchValue2 = ref(false);
let oneDate = ref(0);
let one2Date = ref(0);
let sliderValue5 = ref(1);
let sliderValue6 = ref(3);
let sliderValue7 = ref(1);
let sliderValue8 = ref(3);
let switchValue3 = ref(false);
let input1 = ref("");
let switchValue4 = ref(false);
let sliderValue9 = ref(1);
let input2 = ref("");
let sliderValue10 = ref(3);
let sliderValue11 = ref(3);
let sliderValue12 = ref(3);
let switchValue5 = ref(false);
let input3 = ref("");
let input4 = ref("");
let input5 = ref("");
let input6 = ref("");
let input7 = ref("");
let input8 = ref("");
let input9 = ref("");
let input10 = ref("");
let input11 = ref("");
let input12 = ref("");
let input13 = ref("");
let identity = ref("");
const sceneTableData = ref([]);

let district = ref("");
let tag = ref("");
let group = ref("");
let num = ref("");
let radio5 = ref("reportSetting");
let scene = ref("");
let sceneOptions = ref([
  { value: 1, label: "场景1" },
  { value: 2, label: "场景2" },
  { value: 3, label: "场景3" },
  { value: 4, label: "场景4" },
  { value: 5, label: "场景5" },
  { value: 6, label: "场景6" },
  { value: 7, label: "场景7" },
  { value: 8, label: "场景8" },
  { value: 9, label: "场景9" },
  { value: 10, label: "场景10" },
  { value: 11, label: "场景11" },
  { value: 12, label: "场景12" },
]);
let carryOptions = ref([
  { value: "1,2,3,4,5,6,7", label: "每天执行" },
  { value: "1", label: "每周一执行" },
  { value: "2", label: "每周二执行" },
  { value: "3", label: "每周三执行" },
  { value: "4", label: "每周四执行" },
  { value: "5", label: "每周五执行" },
  { value: "6", label: "每周六执行" },
  { value: "7", label: "每周日执行" },
]);
let carryvalue = ref("");
let transferScene = ref("");
let sceneVisible = ref(true);
let isEdit = false;
let typeOpt = ref("400");
let searchFlag = ref(false);
let searchHtml = ref("网关搜灯");
let iconFlag = ref(false);

const outLinght = () => {
  if (searchFlag.value) {
    searchHtml.value = "搜灯中";
    iconFlag.value = true;
  }
};

const mouLight = () => {
  if (searchFlag.value) {
    searchHtml.value = "停止搜灯";
    iconFlag.value = false;
  }
};

let timer2 = null;
const searchLight = () => {
  window.clearInterval(timer);
  data.loading2 = false;
  if (district.value === "") {
    ElMessage.error("区号不能为空");
    return false;
  }
  searchFlag.value = !searchFlag.value;
  if (searchFlag.value == true) {
    searchHtml.value = "搜灯中";
    iconFlag.value = true;
  } else {
    searchHtml.value = "网关搜灯";
    iconFlag.value = false;
    window.clearInterval(timer2);
    let params = {
      deviceFid: gateway.value,
      mesh: {
        code: 400,
        deviceName: gateway.value,
        area: district.value,
        address: district.value,
        action: "stopScan",
      },
    };
    if (gateway.value === "") {
      for (let i = 0; i < gatewayList.value.length; i++) {
        params.deviceFid = gatewayList.value[i].id;
        params.mesh.deviceName = gatewayList.value[i].id;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
          })
          .catch((err) => { });
      }
    } else {
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
        })
        .catch((err) => { });
    }
    return false;
  }
  let params = {
    deviceFid: gateway.value,
    mesh: {
      code: 400,
      deviceName: gateway.value,
      area: district.value,
      address: district.value,
      action: "scan",
    },
  };
  if (gateway.value === "") {
    for (let i = 0; i < gatewayList.value.length; i++) {
      params.deviceFid = gatewayList.value[i].id;
      params.mesh.deviceName = gatewayList.value[i].id;
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
        })
        .catch((err) => { });
    }
  } else {
    $axios
      .post("/operation/mesh", params)
      .then((res) => {
        data.loading = false;
      })
      .catch((err) => { });
  }

  timer2 = window.setInterval(function () {
    if (iconFlag.value == false || dialogVisible2.value == false) {
      window.clearInterval(timer2);
    }
  }, 1000);
};

const handleClose = () => { };

const handLight = () => {
  data.tableData2.push({
    macaddress: "",
    areaCode: "",
    groupName: "",
    deviceIndex: "",
    deviceType: "",
    updateTime: dateFormat("YYYY-mm-dd HH:MM:SS", new Date()),
    flag: true,
    action: 0,
  });
};

// 入参 fmt-格式 date-日期
const dateFormat = (fmt, date) => {
  let ret;
  const opt = {
    "Y+": date.getFullYear().toString(), // 年
    "m+": (date.getMonth() + 1).toString(), // 月
    "d+": date.getDate().toString(), // 日
    "H+": date.getHours().toString(), // 时
    "M+": date.getMinutes().toString(), // 分
    "S+": date.getSeconds().toString(), // 秒
    // 有其他格式化字符需求可以继续新增，必须转化成字符串
  };
  for (let k in opt) {
    ret = new RegExp("(" + k + ")").exec(fmt);
    if (ret) {
      fmt = fmt.replace(ret[1], ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0"));
    }
  }
  return fmt;
};

const changeWorkDay = (val) => {
  if (scenModel.data.chooseWorkDay[scenModel.data.chooseWorkDay.length - 1] == "1,2,3,4,5,6,7") {
    scenModel.data.chooseWorkDay = ["1,2,3,4,5,6,7"];
  } else {
    var i = scenModel.data.chooseWorkDay.indexOf("1,2,3,4,5,6,7");
    if (i >= 0) {
      scenModel.data.chooseWorkDay.splice(i, 1);
    }
  }
};

const addScene = () => {
  sceneVisible.value = !sceneVisible.value;
  scenModel.data = {
    chooseWorkDay: [],
    startTime: "08:00",
    operateInfo: [],
  };
  carryvalue.value = "";
  transferScene.value = 1;
  isEdit = true;
};
let lampVisible = ref(false);
let timeLamp = null;

const addingLamp = () => {
  lampVisible.value = true;
};

const deleteTag = (i) => {
  ElMessageBox.confirm("是否删除此条记录?", "提示").then(() => {
    scenModel.data.operateInfo.splice(i, 1);
    scenModel.data.operateInfoObj.splice(i, 1);
  });
};

const send = (action, value) => {
  if (action == "setAreaAddress" && area.value != 400) {
    ElMessage.error("只能在区操作下修改");
    return;
  }
  if (action == "setClusterAddress" && area.value != 200) {
    ElMessage.error("只能在群组操作下修改");
    return;
  }

  if (action == "setNumberAddress" && area.value != 100) {
    ElMessage.error("只能在单灯操作下修改");
    return;
  }
  if (action == "setNumberAddress" && area.value == 100 && num.value == "") {
    ElMessage.error("原'号'信息不能为空");
    return;
  }
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: area.value,
      deviceName: pid.value,
      area: district.value,
      address: "00 00",
      action: action,
      params: value,
      identity: identity.value,
    },
  };

  if (area.value == 400) {
    params.mesh.address = district.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }

  if (area.value == 100) {
    params.mesh.address = num.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
  }
  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }
  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }
  if (area.value == "") {
    params.mesh.area = "00 00";
    params.mesh.code = "400";
  }
  layer.msg("正在请求中....", { time: 0 });
  if (gateway.value == "" && area.value != "") {
    for (let i = 0; i < gatewayList.value.length; i++) {
      params.mesh.deviceName = gatewayList.value[i].id;
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => {
          layer.msg("请求失败", { time: 500 });
        });
    }
  } else {
    if (area.value == "") {
      for (let i = 0; i < deviceAreaAllList.value.length; i++) {
        params.mesh.address = deviceAreaAllList.value[i].area_code;
        params.mesh.area = deviceAreaAllList.value[i].area_code;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => {
            layer.msg("请求失败", { time: 500 });
          });
      }
    } else {
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => {
          layer.msg("请求失败", { time: 500 });
        });
    }
  }
};

const Everbright = (action) => {
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: area.value,
      deviceName: pid.value,
      area: district.value,
      address: "00 00",
      action: action,
      params: "",
      identity: identity.value,
    },
  };
  if (area.value == 400) {
    params.mesh.address = district.value;

    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }
  if (area.value == 100) {
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
    if (multipleSelection.value.length > 0) {
      params.mesh.address = multipleSelection.value[0].deviceIndex;
    } else {
      params.mesh.address = num.value;
    }
  }
  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }
  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }
  if (area.value == "") {
    params.mesh.area = "00 00";
    params.mesh.code = "400";
  }
  if (gateway.value == "" && area.value != "") {
    for (let i = 0; i < gatewayList.value.length; i++) {
      params.mesh.deviceName = gatewayList.value[i].id;
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else if (gateway.value != "" && area.value != "") {
    params.mesh.deviceName = gateway.value;
    if (area.value == 100 && multipleSelection.value.length > 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(`请求发送成功`, { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    } else {
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else {
    if (area.value == "" && multipleSelection.value.length == 0) {
      for (let i = 0; i < deviceAreaAllList.value.length; i++) {
        params.mesh.area = deviceAreaAllList.value[i].area_code;
        params.mesh.address = deviceAreaAllList.value[i].area_code;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              if (i == deviceAreaAllList.value.length - 1) {
                layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
              }
            } else {
              if (i == deviceAreaAllList.value.length - 1) {
                showLoad(`请求发送失败`, 500);
              }
            }
          })
          .catch((err) => { });
      }
    } else if (area.value == "" && multipleSelection.value.length != 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(`请求发送成功`, { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    }
  }
};

const extinction = (action) => {
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: area.value,
      deviceName: pid.value,
      area: district.value,
      address: "00 00",
      action: action,
      params: "",
      identity: identity.value,
    },
  };
  if (area.value == 400) {
    params.mesh.address = district.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }
  if (area.value == 100) {
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
    if (multipleSelection.value.length > 0) {
      params.mesh.address = multipleSelection.value[0].deviceIndex;
    } else {
      params.mesh.address = num.value;
    }
  }
  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }
  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }
  if (area.value == "") {
    params.mesh.area = "00 00";
    params.mesh.code = "400";
  }
  if (gateway.value == "" && area.value != "") {
    for (let i = 0; i < gatewayList.value.length; i++) {
      params.mesh.deviceName = gatewayList.value[i].id;
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else if (gateway.value != "" && area.value != "") {
    params.mesh.deviceName = gateway.value;
    if (area.value == 100 && multipleSelection.value.length > 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(`请求发送成功`, { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    } else {
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else {
    if (area.value == "" && multipleSelection.value.length == 0) {
      for (let i = 0; i < deviceAreaAllList.value.length; i++) {
        params.mesh.area = deviceAreaAllList.value[i].area_code;
        params.mesh.address = deviceAreaAllList.value[i].area_code;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              if (i == deviceAreaAllList.value.length - 1) {
                layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
              }
            } else {
              if (i == deviceAreaAllList.value.length - 1) {
                showLoad(`请求发送失败`, 500);
              }
            }
          })
          .catch((err) => { });
      }
    } else if (area.value == "" && multipleSelection.value.length != 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(`请求发送成功`, { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    }
  }
};

const flash = (action) => {
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: area.value,
      deviceName: pid.value,
      area: district.value,
      address: "00 00",
      action: action,
      params: "",
      identity: identity.value,
    },
  };
  if (area.value == 400) {
    params.mesh.address = district.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }
  if (area.value == 100) {
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
    if (multipleSelection.value.length > 0) {
      params.mesh.address = multipleSelection.value[0].deviceIndex;
    } else {
      params.mesh.address = num.value;
    }
  }
  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }
  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }
  if (area.value == "") {
    params.mesh.area = "00 00";
    params.mesh.code = "400";
  }
  if (gateway.value == "" && area.value != "") {
    for (let i = 0; i < gatewayList.value.length; i++) {
      params.mesh.deviceName = gatewayList.value[i].id;
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else if (gateway.value != "" && area.value != "") {
    params.mesh.deviceName = gateway.value;
    if (area.value == 100 && multipleSelection.value.length > 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(`请求发送成功`, { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    } else {
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else {
    if (area.value == "" && multipleSelection.value.length == 0) {
      for (let i = 0; i < deviceAreaAllList.value.length; i++) {
        params.mesh.area = deviceAreaAllList.value[i].area_code;
        params.mesh.address = deviceAreaAllList.value[i].area_code;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              if (i == deviceAreaAllList.value.length - 1) {
                layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
              }
            } else {
              if (i == deviceAreaAllList.value.length - 1) {
                showLoad(`请求发送失败`, 500);
              }
            }
          })
          .catch((err) => { });
      }
    } else if (area.value == "" && multipleSelection.value.length != 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(`请求发送成功`, { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    }
  }
};

const stopFlash = (action) => {
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: area.value,
      deviceName: pid.value,
      area: district.value,
      address: "00 00",
      action: action,
      params: "",
      identity: identity.value,
    },
  };
  if (area.value == 400) {
    params.mesh.address = district.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }
  if (area.value == 100) {
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
    if (multipleSelection.value.length > 0) {
      params.mesh.address = multipleSelection.value[0].deviceIndex;
    } else {
      params.mesh.address = num.value;
    }
  }
  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }
  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }
  if (area.value == "") {
    params.mesh.area = "00 00";
    params.mesh.code = "400";
  }
  if (gateway.value == "" && area.value != "") {
    for (let i = 0; i < gatewayList.value.length; i++) {
      params.mesh.deviceName = gatewayList.value[i].id;
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else if (gateway.value != "" && area.value != "") {
    params.mesh.deviceName = gateway.value;
    if (area.value == 100 && multipleSelection.value.length > 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(`请求发送成功`, { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    } else {
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else {
    if (area.value == "" && multipleSelection.value.length == 0) {
      for (let i = 0; i < deviceAreaAllList.value.length; i++) {
        params.mesh.area = deviceAreaAllList.value[i].area_code;
        params.mesh.address = deviceAreaAllList.value[i].area_code;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              if (i == deviceAreaAllList.value.length - 1) {
                layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
              }
            } else {
              if (i == deviceAreaAllList.value.length - 1) {
                showLoad(`请求发送失败`, 500);
              }
            }
          })
          .catch((err) => { });
      }
    } else if (area.value == "" && multipleSelection.value.length != 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(`请求发送成功`, { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    }
  }
};

const dormancy = (action) => {
  let params = {
    deviceFid: pid.value,
    mesh: {
      code: area.value,
      deviceName: pid.value,
      area: district.value,
      address: "00 00",
      action: action,
      params: "",
      identity: identity.value,
    },
  };
  if (area.value == 400) {
    params.mesh.address = district.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }
  if (area.value == 100) {
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
    if (multipleSelection.value.length > 0) {
      params.mesh.address = multipleSelection.value[0].deviceIndex;
    } else {
      params.mesh.address = num.value;
    }
  }
  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }
  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }
  if (area.value == "") {
    params.mesh.area = "00 00";
    params.mesh.code = "400";
  }
  if (gateway.value == "" && area.value != "") {
    for (let i = 0; i < gatewayList.value.length; i++) {
      params.mesh.deviceName = gatewayList.value[i].id;
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else if (gateway.value != "" && area.value != "") {
    params.mesh.deviceName = gateway.value;
    if (area.value == 100 && multipleSelection.value.length > 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(`请求发送成功`, { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    } else {
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => { });
    }
  } else {
    if (area.value == "" && multipleSelection.value.length == 0) {
      for (let i = 0; i < deviceAreaAllList.value.length; i++) {
        params.mesh.area = deviceAreaAllList.value[i].area_code;
        params.mesh.address = deviceAreaAllList.value[i].area_code;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              if (i == deviceAreaAllList.value.length - 1) {
                layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
              }
            } else {
              if (i == deviceAreaAllList.value.length - 1) {
                showLoad(`请求发送失败`, 500);
              }
            }
          })
          .catch((err) => { });
      }
    } else if (area.value == "" && multipleSelection.value.length != 0) {
      for (let i = 0; i < multipleSelection.value.length; i++) {
        let address = multipleSelection.value[i].deviceIndex;
        params.mesh.address = address;
        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => { });
      }
    }
  }
};

const showOper = (strt) => {
  if (strt == undefined) {
    return "";
  } else if (typeof strt === "string") {
    return JSON.parse(strt);
  } else {
    return strt;
  }
};

const changeEnableState = async (row, num) => {
  wmStore.setOperateItem(row);
  const data = await upStateTimingInterface(JSON.parse(JSON.stringify(row)), num);
  if (data.code === 200) {
    ElMessage.success(`定时状态修改${data.message}`);
    getTab2();
  } else {
    ElMessage.error(data.message);
  }
};

const delScen = (row) => {
  if (row.enableState == 1) {
    layer.msg("请先停用再做删除操作！");
    return;
  }
  ElMessageBox.confirm("确认删除?", "提示")
    .then(() => {
      let params = { id: row.id };
      const formData = new FormData();
      formData.append("id", row.id);
      $axios.post("/deviceTimingRule/deleteTimingRule", formData).then((res) => {
        if (res.data.code === 200) {
          layer.msg("删除成功！");
          getTab2();
        } else {
          layer.msg("删除失败!");
        }
      });
    })
    .catch(() => { }); // 新增错误捕获
};
let scenModel = reactive({
  data: {
    chooseWorkDay: "1,2,3,4,5,6,7",
  },
});
let enable = ref(false);
const getRole = (id) => {
  $axios
    .post(`/role/getRole`)
    .then((res) => {
      for (const i of res.data.data) {
        if (i.role_key === "Admin" || i.role_key === "Manager") {
          enable.value = true;
          break;
        }
      }
    })
    .catch((err) => { });
};

const testScen = async (row) => {
  wmStore.setOperateItem(row);
  const data = await testTimingInterface(row);
  if (data.code === 200) {
    ElMessage.success(`发送${data.message}, 请观察现场状态`);
  } else {
    ElMessage.error(data.message);
  }
};

const editScen = (row) => {
  if (!(row.chooseWorkDay instanceof Array)) {
    row.chooseWorkDay = row.chooseWorkDay.split(",");
  }
  scenModel.data = row;
  sceneVisible.value = false;
  isEdit = false;
  if (row.operateInfo && row.operateInfo.length > 0) {
    transferScene.value = row.operateInfo[0].params;
  } else {
    transferScene.value = "";
  }
};
const changeTransferScene = () => {
  scenModel.data.operateInfo.forEach(element => {
    element.params = transferScene.value
  });
  scenModel.data.operateInfoObj = Array.from(new Set(scenModel.data.operateInfo));
}
const submitScen = async () => {
  console.log('submitScen->', scenModel.data.chooseWorkDay)
  if (scenModel.data.ruleTitle == undefined || scenModel.data.ruleTitle == "") {
    ElMessage.error("任务名称不能为空！");
    return;
  }
  if (scenModel.data.operateInfo == undefined || scenModel.data.operateInfo.length == 0) {
    ElMessage.error("操作灯组不能为空！");
    return;
  }
  if (scenModel.data.chooseWorkDay === null || scenModel.data.chooseWorkDay.length == 0) {
    ElMessage.error("执行模式不能为空！");
    return;
  }
  dsLoading.value = true;
  const res = await upMeshTimingRule(pid.value, scenModel.data, isEdit, wsStore.projectId);
  dsLoading.value = false;
  console.log("resres->", res);
  if (res) {
    ElMessage.success(`${isEdit ? "新增" : "编辑"}成功`);
    sceneVisible.value = true;
    getTab2();
  } else {
    ElMessage.error(`系统异常${res.msg}`);
  }
};

const showScope = (row) => {
  if (row.operateInfo && row.operateInfo.length > 0) {
    let obj = sceneOptions.value.filter((item) => {
      if (typeof row.operateInfo === "string") {
        return JSON.parse(row.operateInfo)[0].params == item.value;
      }
      return row.operateInfo[0].params == item.value;
    });
    if (obj.length > 0 && obj[0].label) {
      return obj[0].label;
    }
  }
};

const showTime = (row) => {
  if (row.chooseWorkDay == "1,2,3,4,5,6,7") {
    return `<div>每天${row.startTime}执行</div>`;
  }
  let arr = [];
  if (row.chooseWorkDay.length > 1 && !(row.chooseWorkDay instanceof Array)) {
    arr = row.chooseWorkDay.split(",");
  } else if (row.chooseWorkDay.length == 1) {
    arr = [row.chooseWorkDay];
  } else {
    arr = row.chooseWorkDay;
  }
  let str = "";
  for (let i = 0; i < arr.length; i++) {
    let wek = arr[i];
    if (arr[i] == 1) {
      wek = "一";
    } else if (arr[i] == 2) {
      wek = "二";
    } else if (arr[i] == 3) {
      wek = "三";
    } else if (arr[i] == 4) {
      wek = "四";
    } else if (arr[i] == 5) {
      wek = "五";
    } else if (arr[i] == 6) {
      wek = "六";
    } else if (arr[i] == 7) {
      wek = "日";
    }
    if (wek) {
      str += `<div>每周${wek}${row.startTime}执行</div>`;
    }
  }
  return str;
};

const showdisb = (i) => {
  if (scenModel.data.chooseWorkDay == `1,2,3,4,5,6,7` && i > 0) {
    return true;
  } else if (scenModel.data.chooseWorkDay == `1,2,3,4,5,6,7` && i == 0) {
    return false;
  } else if (scenModel.data.chooseWorkDay.length > 0 && scenModel.data.chooseWorkDay.length < 8 && i != 0) {
    return false;
  } else if (scenModel.data.chooseWorkDay.length == 0) {
    return false;
  } else if (scenModel.data.chooseWorkDay.length > 0 && scenModel.data.chooseWorkDay.length < 8 && i == 0) {
    return true;
  } else {
    return true;
  }
};

const groupAndSort = (groupFields, sortFields, list) => {
  if (Array.isArray(list) && list.length <= 0) {
    return [];
  }
  let tempList = [];
  list = sortByFields(groupFields, list);
  let tempGroupValue = list[0][groupFields];
  for (let i = 0; i < list.length; i++) {
    if (!list[i]) {
      continue;
    }
    if (list[i][groupFields] != tempGroupValue) {
      tempGroupValue = list[i][groupFields];
    }
    addObjToList(groupFields, sortFields, tempGroupValue, list[i], tempList);
    list.splice(i, 1);
    i--;
  }
  return tempList;
};

const addObjToList = (groupFields, sortFields, tempGroupValue, obj, list) => {
  let tempLength = list.length;
  for (let i = 0; i < list.length; i++) {
    if (list[i][groupFields] == tempGroupValue && obj[sortFields] <= list[i][sortFields]) {
      list.splice(i, 0, obj);
      return;
    }
  }
  if (tempLength == list.length) {
    list.push(obj);
  }
};

const sortByFields = (sortFields, list) => {
  return list.sort((a, b) => {
    if (a[sortFields] < b[sortFields]) {
      return -1;
    }
    if (a[sortFields] > b[sortFields]) {
      return 1;
    }
    return 0;
  });
};

const createComprisonFunction = (propertyName) => {
  return function (object1, object2) {
    var value1 = object1[propertyName] * 1;
    var value2 = object2[propertyName] * 1;
    if (value1 < value2) {
      return -1;
    } else if (value1 > value2) {
      return 1;
    } else {
      return 0;
    }
  };
};

let mode_0 = ref("场景1");
let mode_1 = ref("");
let mode_2 = ref("");
let mode_3 = ref("");
let mode_4 = ref(0);
let mode_5 = ref(0);
let mode_6 = ref(0);
let mode_7 = ref("0");
let mode_8 = ref("0");
const setScen = () => {
  let str = "";
  //有人亮度
  if (sliderValue_2 != sliderValue.value) {
    str += "<p>有人亮度从" + sliderValue_2 + "%修改为" + sliderValue.value + "%</p>";
  }

  // //无人亮度
  if (sliderValue2_2 != sliderValue2.value) {
    str += "<p>无人亮度从" + sliderValue2_2 + "%修改为" + sliderValue2.value + "%</p>";
  }

  if (sliderValue3_2 != sliderValue3.value) {
    str += "<p>当前色度从" + sliderValue3_2 + "%修改为" + sliderValue3.value + "%</p>";
  }

  if (oneDate_2 != oneDate.value) {
    str += "<p>一段延时从" + oneDate_2 + "秒修改为" + oneDate.value + "秒</p>";
  }

  if (str == "") {
    opFunciont();
  } else {
    ElMessageBox.alert('<div class="tipsbox">' + str + "</div>", "提示", {
      dangerouslyUseHTMLString: true,
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      showCancelButton: true,
    })
      .then(() => {
        opFunciont();
      })
      .catch(() => { });
  }
};

const opFunciont = () => {
  var last = mode_0.value.charAt(mode_0.value.length - 1);
  let obj = {
    code: area.value,
    deviceName: pid.value,
    area: district.value,
    address: "00 00",
    action: "setScene",
    params: {
      LampGroups: [
        {
          Lamps: [],
          Params: {
            LightMode: mode_1.value,
            AlsControlMode: mode_3.value,
            DelayMode: mode_2.value,
            HighBright: mode_4.value + "%",
            StandbyBright: mode_5.value + "%",
            CctBright: mode_6.value + "%",
            DelayTime: mode_7.value + "秒",
            DelayTime2: mode_8.value + "秒",
            SceneNo: last,
          },
        },
      ],
      SceneId: last,
      SceneName: "",
    },
    identity: "",
  };
  let ss = {
    LightMode: mode_1.value,
    AlsControlMode: mode_3.value,
    DelayMode: mode_2.value,
    HighBright: mode_4.value + "%",
    StandbyBright: mode_5.value + "%",
    CctBright: mode_6.value + "%",
    DelayTime: mode_7.value + "秒",
    DelayTime2: mode_8.value + "秒",
    SceneNo: last,
  };
  obj.params = JSON.stringify(ss);

  let params = {
    deviceFid: pid.value,
    mesh: {
      code: area.value,
      deviceName: pid.value,
      area: district.value,
      address: "00 00",
      action: "savetoScene",
      params: last,
      identity: identity.value,
    },
  };

  if (area.value == 400) {
    params.mesh.address = district.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
  }

  if (area.value == 100) {
    params.mesh.address = num.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (num.value == "") {
      ElMessage.error("号不能为空");
      return;
    }
  }

  if (area.value == 200) {
    params.mesh.address = group.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (group.value === "") {
      ElMessage.error("组不能为空");
      return;
    }
  }

  if (area.value == 300) {
    params.mesh.address = tag.value;
    if (district.value === "") {
      ElMessage.error("区不能为空");
      return;
    }
    if (tag.value == "") {
      ElMessage.error("标签不能为空");
      return;
    }
  }

  if (area.value == "") {
    params.mesh.area = "00 00";
    params.mesh.code = "400";
  }
  layer.msg("正在请求中....", { time: 0 });

  if (gateway.value == "" && area.value != "") {
    for (let i = 0; i < gatewayList.value.length; i++) {
      params.mesh.deviceName = gatewayList.value[i].id;
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => {
          layer.msg("请求失败", { time: 500 });
        });
    }
  } else {
    if (area.value == "") {
      for (let i = 0; i < deviceAreaAllList.value.length; i++) {
        params.mesh.address = deviceAreaAllList.value[i].area_code;
        params.mesh.area = deviceAreaAllList.value[i].area_code;

        $axios
          .post("/operation/mesh", params)
          .then((res) => {
            data.loading = false;
            if (res.data.code === 200) {
              layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
            } else {
              showLoad(`请求发送失败`, 500);
            }
          })
          .catch((err) => {
            layer.msg("请求失败", { time: 500 });
          });
      }
    } else {
      $axios
        .post("/operation/mesh", params)
        .then((res) => {
          data.loading = false;
          if (res.data.code === 200) {
            layer.msg(i18n.language === "zh-cn" ? `请求发送成功` : "Request sent successfully", { time: 500 });
          } else {
            showLoad(`请求发送失败`, 500);
          }
        })
        .catch((err) => {
          layer.msg("请求失败", { time: 500 });
        });
    }
  }
};

const changeGroup = () => {
  let obj = {
    groupName: group.value,
    areaCode: district.value,
    deviceIndex: num.value,
  };
  getLampInfo(obj);
};

const changeAistrict = () => {
  changeGroup();
};
let sliderValue_2 = "";
let sliderValue2_2 = "";
let mode_0_2 = "";
let sliderValue3_2 = "";
let oneDate_2 = "";
const getLampInfo = (obj) => {
  let params = { deviceFid: pid.value, ...obj };
  for (let i in params) {
    if (params[i] == "") {
      delete params[i];
    }
  }
  $.get($httpUrl + "/operationDevice/getLampInfo", params, function (res) {
    if (res.data == null) {
      return false;
    }

    //有人亮度
    if (res.data.triggerOpenLightNum != null) {
      sliderValue.value = parseInt(res.data.triggerOpenLightNum.slice(0, -1));
      sliderValue_2 = sliderValue.value;
    }

    //无人亮度
    if (res.data.triggerFloodlightNum != null) {
      sliderValue2.value = parseInt(res.data.triggerFloodlightNum.slice(0, -1));
      sliderValue2_2 = sliderValue2.value;
    }

    //情景模式
    mode_0.value = "场景" + parseInt(res.data.sceneNo);
    mode_0_2 = mode_0.value;

    //当前色度
    sliderValue3.value = res.data.colorTemperature == null ? 0 : res.data.colorTemperature;

    sliderValue3_2 = sliderValue3.value;

    //一段延时
    if (res.data.darkenDelay != null) {
      oneDate.value = parseInt(res.data.darkenDelay.slice(0, -1));
      oneDate_2 = oneDate.value;
    }
  });
};
onMounted(() => {
  total = 0;
  layui.extend({}).use(["jquery", "layer", "form", "table", "slider", "dropdown"], function () {
    $ = layui.jquery;
    layer = layui.layer;
    form = layui.form;
    table = layui.table;
    slider = layui.slider;
    slider1 = layui.slider;
    slider2 = layui.slider;
    dropdown = layui.dropdown;
    maxNum = 3;
    setTimeouts = 2000;
    tipsTime = 1000;
    //渲染滑块
    lightNum = 0;
    slider.render({
      elem: "#slideTest1", //绑定元素
      input: true, //输入框
      min: 0,
      change: function (value) {
        lightNum = value;
      },
    });
    getDeviceAliasAllListFun();
    getList({});
    getRole();
  });
});
</script>

<style lang="scss" scoped>
.Naming {
  display: flex;
  align-items: center;
  height: 100%;
}

.available1 {
  color: orangered;
}

:deep(.selectName .el-input__wrapper) {
  background: none !important;
  box-shadow: none !important;
}

:deep(.selectName .el-select .el-input.is-focus .el-input__wrapper) {
  box-shadow: none !important;
}

:deep(.selectName select) {
  min-width: 80px;
  margin-left: 6px;
}

:deep(.selectName ::-webkit-input-placeholder) {
  color: #fff !important;
}

.dialog-footer {
  text-align: center;
  width: 100%;
  display: block;
}

:deep(.newAdd .el-table__inner-wrapper) {
  border: solid 1px #fff;
}

:deep(.sceneTableData .el-scrollbar__thumb) {
  background: #ccc !important;
}

:deep(.sceneTableData .el-button + .el-button) {
  margin-left: 5px;
}

.newAddTab {
  border: solid 1px #fff;
}
</style>
<style lang="scss" scoped>
.newAdd .el-dialog__header {
  background: #0ec8ec69 !important;
}

.newAdd .el-dialog__header .el-dialog__title {
  color: #fff !important;
}

.el-row {
  padding: 10px 0;
  border-bottom: solid 1px #ddd;
}

.el-row>div {
  align-items: center;
}

.el-row>div.el-col-4:first-child {
  display: flex;
}

.sliderbox {
  display: flex;
  align-items: center;
}

.sliderbox>span {
  margin-left: 20px;
  font-size: 14px;
  display: block;
  width: 30px;
}

.linev .layui-form-label {
  width: 114px;
}

.linev .layui-input-block {
  position: relative;
  top: 17px;
  margin-left: 150px;
}

:deep(.el-switch__label--right span) {
  color: #fff;
}

:deep(.selectName input) {
  color: #fff !important;
  text-align: right;
}

:deep(.el-dialog__title) {
  color: #fff !important;
}

:deep(.wiretab .el-checkbox__input.is-disabled .el-checkbox__inner) {
  background: #ccc;
  border-color: #ccc;
}

:deep(.el-dialog.is-draggable .el-dialog__header) {
  background: #217093;
}

:deep(.dialogPermiss .el-dialog__title) {
  color: #fff !important;
}

:deep(.dialogPermiss .el-dialog__headerbtn .el-dialog__close) {
  color: #fff !important;
}

.searchFlag {
  background: #30ce13;
  border-color: #30ce13;
  cursor: pointer;
  float: right;
  margin-left: 7px;
}

.searchFlag:hover {
  background: #ee2020;
  border-color: #ee2020;
  cursor: pointer;
}

.searchFlagBox {
  display: inline-block;
  cursor: pointer !important;
}

.loa {
  animation: rotating 2s linear infinite;
}

@-webkit-keyframes rotating {
  0% {
    transform: rotate(0);
  }

  to {
    transform: rotate(1turn);
  }
}

@keyframes rotating {
  0% {
    transform: rotate(0);
  }

  to {
    transform: rotate(1turn);
  }
}
</style>
<style>
.newAdd .el-dialog__title {
  color: #fff !important;
}

.el-dialog__body .top .el-row>div {
  display: flex;
}

.top .el-row>div>span {
  display: inline-block;
  width: 100px;
  text-align: right;
  padding-right: 10px;
}

.el-dialog__body .top .el-row>div>span {
  width: auto;
  white-space: nowrap;
  padding: 0 5px;
}

.radiocont .layui-form-radio {
  display: none;
}

.btnbox .top {
  color: #fff;
}

.btnbox .top .el-row {
  padding-right: 38%;
}

.btnbox {
  width: 100%;
}

.tops .el-row>div>span>div {
  margin-left: 5px;
}

.newName {
  display: flex;
  align-items: center;
}

.newName>span {
  display: flex;
  width: 85px;
  text-align: right;
  font-size: 14px;
  padding-right: 10px;
  align-items: center;
  justify-content: right;
}

.newName p {
  padding-left: 30px;
}

.tipsbox p {
  line-height: 180%;
}

.setArea3 {
  padding: 9px 0;
  margin-top: -17px;
}
</style>
<style lang="scss">
.setWirelessdevice {
  display: inline-flex;
}

.layui-layer-wrap .el-radio.el-radio--large .el-radio__label {
  color: #f13131 !important;
}

.top .el-select .el-input__wrapper {
  background: none;
}

.top .el-input__wrapper {
  background: none;
}

::-webkit-input-placeholder {
  color: #ccc !important;
  font-size: 16px;
}

.tops .el-input__inner {
  color: #fff !important;
}

.tops .el-row {
  padding-right: 0% !important;
}

.tops .el-row>div>span {
  width: auto !important;
  margin-top: 10px;
}

.tops .el-row>div {
  display: block;
}

.sceneTableData .cell {
  color: #fff;
}

.sceneTableData td .cell {
  color: #000;
}

.sceneTableData th {
  background: var(--el-color-primary) !important;
}

.sceneVisible {
  width: 100%;
}

.sceneVisible .el-col {
  margin-bottom: 10px;
}

.altcon {
  width: 120px;
  height: 36px;
  background-color: #ecf0f8;
  border-radius: 6px;
  text-align: center;
  line-height: 36px;
  margin-left: 10px;
  font-size: 14px;
  color: #1e62da;
  width: fit-content;
  padding: 0px 6px;
  margin-bottom: 10px;
  display: inline-block;
  cursor: pointer;
}

.operateInfo {
  font-weight: bold;
}

.altconp {
  padding-left: 30px;
}

.top .el-button+.el-button {
  margin-left: 6px;
}

.Actions .el-dialog__header {
  background: none !important;
}

.tipsBox {
  margin-top: 4px;
}

.handLight {
  position: relative;
  top: 5px;
}

.itemTop {
  margin-bottom: 5px;
  display: inline-block;
}

.sli2 {
  width: 88%;
}
</style>
